Guides

VNC port and VNC server on Ubuntu: 5900 + display, TigerVNC, x11vnc, SSH tunnel

VNC port is 5900 plus the display number. Set up a VNC server on Ubuntu 24.04 or 26.04 with TigerVNC or x11vnc, bound to localhost and reached over SSH.

Published ~8 min read
On this page

Short answer: VNC uses TCP port 5900 plus the display number: display :0 listens on 5900, :1 on 5901, :2 on 5902. Port 5800 belonged to the old built-in web server for the Java viewer, which TigerVNC removed in 2019. On Ubuntu, install TigerVNC, keep it on localhost and reach it through an SSH tunnel.

Ubuntu 24.04 · 26.04
sudo apt install tigervnc-standalone-server xfce4
tigervncpasswd                       # VNC password for your user
tigervncserver :1 -localhost yes     # desktop :1 on 127.0.0.1:5901
ss -tlnp | grep 590                  # which VNC ports are listening

# on your computer, then point a viewer at 127.0.0.1:5901
ssh -N -L 5901:127.0.0.1:5901 alice@203.0.113.10

Replace alice and 203.0.113.10 with your user and server. Package names, file paths and options below come from the Ubuntu packages and their manual pages for 24.04 LTS (TigerVNC 1.13.1, x11vnc 0.9.16) and 26.04 LTS (TigerVNC 1.15.0, x11vnc 0.9.17). Both are in the universe repository.

Which port does VNC use?

RFC 6143, the VNC protocol (RFB) specification, says a client contacts the server on TCP port 5900, and that with several servers on one machine, server N typically listens on 5900+N. IANA has assigned only 5900 to RFB; the rest is convention. Common VNC servers and viewers follow that convention, which is why the display number and the port are interchangeable.

PortWhat listens thereNote
5900Display :0: a shared physical screen (x11vnc, macOS Screen Sharing)The only port IANA assigned to VNC
5901Display :1: the first TigerVNC virtual desktopWhat tigervncserver picks first, usually
5902, 5903, ...Displays :2, :3 and upOne port per desktop
5800 + NOld HTTP server that handed out a Java applet viewerGone from TigerVNC since 1.10.0
6000 + NX11 itself for display N, not VNCKeep closed

Viewers read host:1 as display 1, so port 5901. To give a raw port, TigerVNC Viewer takes a double colon: 127.0.0.1::5901. Its address parser treats a number below 100 after a single colon as a display and anything larger as a port, so host:5901 also reaches 5901 in TigerVNC. Other viewers may read it differently; the double colon is the unambiguous form.

What happened to port 5800?

Older VNC servers ran a small web server on 5800 plus the display number, which served a Java applet so a browser could act as the viewer. TigerVNC 1.7's Xvnc manual still documents it as -httpPort, "Default is 5800 plus the display number". The TigerVNC 1.10.0 release notes (November 2019) removed this Java web server because most browsers no longer support applets. The Xtigervnc manual for 24.04 has no HTTP option at all. x11vnc still carries -http and -httpport for the applet, but no current browser runs it, so 5800 does not need to be open.

How to change the VNC port

  • Pick another display number. tigervncserver :7 listens on 5907. This is the clean way, because viewers and tunnels keep the 5900+N rule.
  • TigerVNC with any port: tigervncserver :1 -rfbport 5999. The manual: "The default is 5900 plus the display number".
  • x11vnc: -rfbport 5999, or -N to use 5900+N for X display :N.

A new port is not a security measure on its own. Change the tunnel or firewall rule to match, and check the result with ss -tlnp. The list of common ports shows what else lives near 5900.

Set up TigerVNC on Ubuntu 24.04 and 26.04

TigerVNC's standalone server starts a desktop of its own in memory, with no monitor and no display manager. That is what a VPS or a dedicated server without a screen needs: there is no :0 to share, so TigerVNC creates :1. Run it as a normal user, not as root; sudo is only needed to install it (see creating a sudo user).

  1. 1Install the server and a light desktop
    sudo apt install tigervnc-standalone-server xfce4. tigervnc-tools, which holds tigervncpasswd, comes along as a recommended package.
  2. 2Set a VNC password
    Run tigervncpasswd as the desktop user. Its manual asks for at least six characters and says only the first eight are significant; RFC 6143 VNC authentication truncates the password to eight, which is one reason it stays behind SSH.
  3. 3Choose the session and keep localhost
    Put the two lines below in your user config. xfce matches /usr/share/xsessions/xfce.desktop.
  4. 4Start and check it
    tigervncserver :1, then tigervncserver -list. Stop it with tigervncserver -kill :1.
Ubuntu 24.04
mkdir -p ~/.vnc
printf '%s\n' '$session = "xfce";' '$localhost = "yes";' > ~/.vnc/tigervnc.conf
Ubuntu 26.04
mkdir -p ~/.config/tigervnc
printf '%s\n' '$session = "xfce";' '$localhost = "yes";' > ~/.config/tigervnc/config.pl

The Ubuntu wrapper already listens on localhost only when you give no security options: its manual says it stays on localhost unless the security types include TLS or X509. Writing $localhost = "yes" makes that explicit, so a later change of security types cannot open it by accident. Settings are read in this order: /etc/tigervnc/vncserver-config-defaults, your user file, the command line, and last /etc/tigervnc/vncserver-config-mandatory, which overrides everything.

What differs between 24.04 and 26.04

ItemUbuntu 24.04 LTSUbuntu 26.04 LTS
TigerVNC package1.13.11.15.0 (Debian 13 has 1.15.0 too)
User folder~/.vnc~/.config/tigervnc
Password file~/.vnc/passwd~/.config/tigervnc/passwd
User config~/.vnc/tigervnc.conf~/.config/tigervnc/config.pl
Startup script~/.vnc/Xtigervnc-session~/.config/tigervnc/xstartup
Server log~/.vnc/HOST:1.log~/.config/tigervnc/HOST:1.log
Session helper log (systemd)~/.vnc/HOST:1.log~/.local/state/tigervnc/HOST:1.log
systemd unit/lib/systemd/system/tigervncserver@.service/usr/lib/systemd/system/tigervncserver@.service

After an upgrade to 26.04 you do not have to move anything by hand. When ~/.config/tigervnc does not exist yet, the 1.15 wrapper moves ~/.vnc there, leaves a symlink behind and renames tigervnc.conf to config.pl and Xtigervnc-session to xstartup. If ~/.vnc still exists and ~/.local/state/tigervnc does not, the session helper used by the systemd unit logs a warning to the system log that ~/.vnc is deprecated and writes its own log there instead.

Start the VNC server at boot with tigervncserver@:1

The package ships a template unit. Its header lists the steps: map a display number to a user in /etc/tigervnc/vncserver.users, then enable tigervncserver@:<display>.service. The unit runs /usr/libexec/tigervncsession-start, which looks up the user and starts tigervncsession; that in turn runs the same tigervncserver wrapper as the user, so the config file above still applies. Set the password first: without a password file the wrapper tries to prompt for one, and a service has no terminal.

Ubuntu 24.04 · 26.04
echo ':1=alice' | sudo tee -a /etc/tigervnc/vncserver.users
sudo systemctl enable --now tigervncserver@:1.service
systemctl status tigervncserver@:1.service
ss -tlnp | grep 5901                 # should show 127.0.0.1:5901

The file's syntax is <display>=<username>, one line per user, so :2=bob gives a second user port 5902. If the service fails at once, journalctl -u tigervncserver@:1 and the logs from the table say why; a display without a line in the file stops with "No user configured for display".

Connect through an SSH tunnel

The unit file's own comment says not to run the service on an untrusted network and to tunnel instead. On your computer:

Linux · macOS · Windows PowerShell
ssh -N -L 5901:127.0.0.1:5901 alice@203.0.113.10
# leave it open; viewer address: 127.0.0.1:1 or 127.0.0.1::5901
  • On Windows 10 (1809 or later) and Windows 11 the same line works with Microsoft's built-in OpenSSH client; if ssh is missing, add OpenSSH Client under Optional features (see SSH on Windows).
  • To open it with a short name, put a LocalForward 5901 127.0.0.1:5901 line under the host in your SSH config file.
  • TigerVNC Viewer (package tigervnc-viewer on Ubuntu; Windows and macOS builds are linked from tigervnc.org) has a -via option that opens the SSH tunnel for you.

Share an existing desktop with x11vnc

TigerVNC creates a new desktop. To see and control the screen someone is already logged in to, use x11vnc: it attaches to a running X display, usually :0, and probes for a free port starting at 5900. By default it exits when the viewer disconnects and does not allow shared connections; -forever and -shared change that.

as the logged-in desktop user, over SSH
sudo apt install x11vnc
x11vnc -storepasswd                  # writes ~/.vnc/passwd
x11vnc -display :0 -auth guess -localhost -usepw -forever -shared

-localhost also makes x11vnc listen on 127.0.0.1 only, -usepw uses ~/.vnc/passwd, and -auth guess tries to find the X authority file. Tunnel port 5900 the same way as above.

If you have to expose the port: firewall first

RFC 6143 calls classic VNC authentication "cryptographically weak", and the base protocol encrypts nothing. If viewers really cannot use SSH, start the server with -localhost no. The Ubuntu wrapper then offers VncAuth and TLSVnc. TLSVnc encrypts without a certificate, so the viewer cannot check which server it reached; -SecurityTypes X509Vnc uses a certificate, which the wrapper generates self-signed on first use unless you pass -X509Cert and -X509Key. Any TLS or X509 type in the list also switches the default to listening on all addresses. Then allow the port from your own address only:

ufw
sudo ufw allow proto tcp from 198.51.100.7 to any port 5901
sudo ufw status numbered

The ufw guide covers source rules in more detail. Never leave 5900 to 5910 open to everyone: the VNC password check is weak and uses at most eight characters.

Common problems

  • Connection refused from outside, works through the tunnel: correct, the server listens on 127.0.0.1. Use the tunnel.
  • Grey or empty screen: no desktop session started. Set $session to a name from /usr/share/xsessions, kill the display and start it again; the manual notes a new startup script does not affect a running desktop.
  • Display already in use: tigervncserver :1 exits if :1 is taken. The wrapper counts a display as taken when something listens on its VNC port or on the X server port 6000+N, or when /tmp/.X1-lock or /tmp/.X11-unix/X1 exists. tigervncserver -list shows what runs, and -list -cleanstale also clears stale entries left by crashed servers.
  • Wrong port in the viewer: in TigerVNC Viewer host:1 and host::5901 both mean port 5901. If another viewer fails with host:5901, use one of those two forms.

Frequently asked

What port does VNC use?

VNC uses TCP port 5900 plus the display number, so display :0 is 5900, :1 is 5901 and :2 is 5902. RFC 6143 names 5900 as the port IANA assigned to the protocol; the higher ports are the convention for several servers on one machine. In TigerVNC Viewer, host:1 means port 5901 and host::5901 gives the port directly.

What is port 5800 used for in VNC?

Port 5800 plus the display number was the built-in web server that older VNC servers used to hand a Java applet viewer to a browser. TigerVNC removed it in version 1.10.0 in 2019 because most browsers no longer support applets. A current VNC server only needs its 5900+N port.

How do I start a TigerVNC server at boot on Ubuntu?

Install tigervnc-standalone-server, set the user's password with tigervncpasswd, and add a line such as :1=alice to /etc/tigervnc/vncserver.users. Then run sudo systemctl enable --now tigervncserver@:1.service. The desktop for alice then starts at every boot on port 5901, on localhost only unless you change the security settings.

Is it safe to open port 5900 to the internet?

No. Classic VNC authentication uses only the first eight characters of the password and RFC 6143 calls it cryptographically weak, and the base protocol encrypts nothing. Keep the server on 127.0.0.1 and reach it with ssh -L 5901:127.0.0.1:5901. If you must expose it, allow the port only from your own IP address in the firewall.

Related articles

All guides