localhost:5900 — VNC Remote Desktop

VNC (Virtual Network Computing) provides graphical remote desktop access. Port 5900 is the base port for VNC display 0. Each additional display increments by 1: display 1 = port 5901, display 2 = 5902, etc. VNC is platform-agnostic — you can control a Linux server from Windows, a Mac from Linux, or any combination.

VNC Port Mapping

Display NumberPortTypical Use
:05900Physical display / primary session
:15901First virtual display
:25902Second virtual display
:3+5903+Additional displays

VNC Implementations

SoftwarePlatformLicenseBest For
RealVNCWin/Mac/Linux/PiFree/CommercialEasy setup, cloud connections, cross-platform
TigerVNCLinux/WinFree (GPL)High performance Linux remote desktop
TightVNCWin/LinuxFree (GPL)Windows server/client, compressed protocol
LibVNCServerLinuxFree (LGPL)Embedded in many IoT devices
macOS Screen SharingMacBuilt-inMac-to-Mac VNC, Apple Remote Desktop

Linux — TigerVNC Setup

# Install
sudo apt install tigervnc-standalone-server tigervnc-common

# Set VNC password
vncpasswd

# Start a VNC server on display :1 (port 5901)
vncserver :1 -geometry 1920x1080 -depth 24

# Stop the server
vncserver -kill :1

# ~/.vnc/xstartup — configure desktop environment
#!/bin/bash
export XKL_XMODMAP_DISABLE=1
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
exec startxfce4  # or gnome-session, startlxde, etc.

Connecting to a VNC Server

# Most VNC viewers accept: host:display or host:port
# Examples:
192.168.1.100:0      # display 0 (port 5900)
192.168.1.100:5901   # explicit port 5901 (display 1)
192.168.1.100::5901  # double colon = explicit port in some clients

# From command line (if vncviewer installed)
vncviewer 192.168.1.100:1

Secure VNC Over SSH Tunnel

VNC traffic is minimally encrypted or unencrypted depending on implementation. Always tunnel VNC over SSH when connecting over the internet or untrusted networks:

# On your local machine — create SSH tunnel
# This maps localhost:5901 to the remote server's localhost:5900
ssh -L 5901:localhost:5900 user@remote-server-ip -N

# Then connect your VNC client to:
localhost:5901

# Or tunnel display 1 (port 5901 on server)
ssh -L 5902:localhost:5901 user@remote-server-ip -N

macOS — Enable Screen Sharing (Built-in VNC)

  1. System Settings → General → Sharing
  2. Enable Screen Sharing
  3. Click the (i) next to Screen Sharing → you can set a VNC password here
  4. Other Macs can connect via Finder → Network → select Mac → Share Screen
  5. VNC clients on other platforms: connect to the Mac's IP on port 5900

Windows — Enable VNC Access

Windows does not include VNC built-in. Options:

  • RealVNC Connect: Download from realvnc.com, install the Server component. Free tier allows 3 cloud connections.
  • TightVNC: Free, simple, lightweight. Install TightVNC Server, set a password, and it listens on port 5900.
  • Windows Remote Desktop (RDP): On port 3389 — not VNC but often a better option for Windows-to-Windows remote access.

Troubleshooting

Connection refused on 5900: No VNC server is running on that host, or it is bound to localhost only (won't accept remote connections). Check: ss -tlnp | grep 59 to see which addresses VNC is listening on.

Black screen: The VNC server started but the desktop environment did not launch. Check the ~/.vnc/xstartup file — it must start your desktop environment and exit normally. Make it executable: chmod +x ~/.vnc/xstartup.

Very slow: VNC transmits screen pixels over the network. Use a compressed encoding (TigerVNC supports Tight encoding which compresses well). Reduce display resolution or color depth. For slower connections, RDP typically performs better than VNC.