systems-configuration

How to Start VNC Server: Configuration, Commands, and Best Practices

To start vncserver on most platforms, install the TightVNC or TigerVNC package, then run vncserver on the console or via SSH to create a new desktop session. The command generat...

Mara Ellison
How to Start VNC Server: Configuration, Commands, and Best Practices

How to Start VNC Server and Confirm It Is Running

To start vncserver on most platforms, install the TightVNC or TigerVNC package, then run vncserver on the console or via SSH to create a new desktop session. The command generates a startup log, a default xstartup script, and a display number-based port (5900 + display), and it prints the exact command to use for client connection. On systemd systems, you can also enable a service unit for autostart. This guide explains the commands, configuration files, ports, and best practices to reliably start and manage VNC server sessions.

Understand VNC Server Startup Components

A VNC server is not a single universal binary; it is typically implemented by TightVNC, TigerVNC, or x11vnc, each with slightly different defaults. All of them bind to display-specific ports (display :N → TCP 5900+N) and optionally listen on loopback-only for initial configuration. Understanding the installed package, the display number, and the xstartup script is essential to start vncserver predictably.

Key Terms at a Glance

TermVerified DetailSource Type
vncserverScript provided by TightVNC/TigerVNC to start and manage VNC sessionsPackage documentation
Display numberMaps to TCP port 5900+N and the initial desktop sessionVNC protocol convention
xstartupPer-display startup script defining the window manager and applicationsVNC server configuration
VNCSessionDesktop environment selection configured in xstartupImplementation-specific
Loopback listenerRestricting VNC port to localhost until explicitly enabled for remote accessSecurity best practice

Install the Required Packages

Before you can start vncserver, install the server package and optionally a lightweight desktop environment if the system does not already have one. On Debian/Ubuntu, install tightvncserver or tigervnc-standalone-server plus xfce4 or similar. On RHEL/CentOS, install tigervnc-server and tigervnc-server-module. On modern distributions, choose the package that matches your desired desktop session.

Platform-Specific Install Commands

  • Debian/Ubuntu: apt-get update && apt-get install -y tigervnc-standalone-server xfce4
  • RHEL/CentOS: yum install -y tigervnc-server xfce4
  • Fedora: dnf install -y tigervnc-server xfce4

Start vncserver for the First Time

To start vncserver interactively, SSH into the machine and run vncserver without arguments. The command creates a new default session, prompts for a VNC password (not the OS password), writes a ~/.vnc/hostname:display.pid config directory, and outputs a summary that includes the display number, listening port, and recommended command to stop the session. On subsequent runs, specify a display such as vncserver :1 to avoid using the next available display.

Typical First-Time Output

After running vncserver, you will see output similar to the following sequence: a welcome message, a prompt for the password, confirmation of the xstartup script path, and a summary line such as “New 'host:1 (user)' desktop is host:1”. The summary indicates the display number and the ports in use. Use the exact command shown in the summary to connect from a VNC client, and verify that port 5901 (for :1) is reachable through your firewall or tunnel.

Configure xstartup for Consistent Sessions

The xstartup script under ~/.vnc/xstartup determines what happens when vncserver starts: it launches a window manager and any desktop environment components. A reliable xstartup typically unsets any conflicting window managers, starts a standard session via exec, and falls back to a minimal session if needed. For TigerVNC on many distributions, the default script works, but you may need to adjust it to start xfce4, startlxqt, or startkde depending on your installed desktop.

Example xstartup Snippet

# typical ~/.vnc/xstartup
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
exec /etc/X11/Xsession

Replace the exec line with exec startxfce4 or exec startkde if you prefer a specific desktop. Ensure the script is executable (chmod +x ~/.vnc/xstartup). Restart the session by stopping and starting vncserver so the new configuration takes effect.

Use Systemd to Manage Autostart and Reliable Startup

To start vncserver automatically at boot or per user, create a systemd user service. This is more robust than relying on manual commands or cron @reboot. A unit typically runs vncserver :1 as your user, sets environment variables, and optionally waits for graphical targets. Use systemctl --user enable vncserver@.service and systemctl --user start vncserver@1 to control the service. Check journalctl for troubleshooting and ensure the service file points to the correct display and user.

Example vncserver@.service Unit (User Scope)

AttributeVerified DetailSource Type
ExecStart/usr/bin/vncserver :1 -localhost noPackage default
ExecStop/usr/bin/vncserver -kill :1Package default
EnvironmentDISPLAY=:1Systemd best practice
UseryouruserDeployment-specific
WorkingDirectory/home/youruserDeployment-specific

Secure VNC Server on Startup

Security defaults vary: some packages bind to localhost only until you explicitly allow external access, but never assume this. To secure startup, keep VNC listening on loopback by default and use SSH tunneling for remote access. Set a strong VNC password with vncpasswd, prefer TLS via SSH tunnel or stunnel, and restrict firewall rules to trusted IPs. If you must listen on all interfaces, enable tight encryption where supported and avoid exposing VNC directly to the internet.

Security Checklist for vncserver Start

  • Set a VNC password separate from your OS password
  • Start with loopback-only access, then selectively allow remote IPs
  • Use SSH tunneling: ssh -L 5901:localhost:5901 user@host
  • Enable firewall rules allowing only trusted sources on the VNC port
  • Disable unnecessary X extensions and monitor logs for failed logins

Verify That VNC Server Is Running After Start

After you start vncserver, confirm it is running with a few simple checks. Use vncserver -list to see active sessions and display numbers, ps aux | grep Xtightvnc or ps aux | grep Xvnc to verify processes, and check that the expected port is listening with sS -tlnp | grep 590. Inspect ~/.vnc/hostname:display.log for errors in xstartup or desktop launch failures.

Verification Commands Quick Reference

CommandPurposeOutcome
vncserver -listShow running VNC sessionsDisplays active displays and PIDs
ss -tlnp | grep 590Check listening TCP portsConfirms ports 5901, 5902, … are open
tail ~/.vnc/*.logView server logsReveances startup errors

Automate Start on Boot and Recover from Failures

To ensure vncserver starts on boot, enable the systemd unit or, on servers without systemd, add a safe launch script via cron @reboot that checks for an existing session before starting a new one. Use a small wrapper to avoid multiple instances on the same display and to log failures. If a session fails to start, inspect the latest ~/.vnc/*.log, verify DISPLAY and PATH, ensure the window manager is installed, and confirm no other process is bound to the same port.

Common Pitfalls When Starting VNC Server

Common issues include: choosing a display that is already in use, missing or broken xstartup causing blank sessions, incorrect permissions on ~/.vnc directory (should be 0700), missing desktop environment packages, and firewall rules blocking port 5900+N. On Wayland systems, you may need to configure a compatible session or use X11 translation; some distributions restrict direct VNC access for root, so always run as an unprivileged user for routine desktop sessions.