How to Use the VNC Remote Desktop Functionality on Linux

Commands, Syntax, and Examples

Two businesswomen looking at a computer

Stockbyte/Getty Images

Virtual Network Computing (VNC) is a remote display system that enables you to start a desktop environment on one machine and access it from other computers through an Internet connection. You can set up persistent desktops which will be maintained while you disconnect, so you can continue working exactly where you left off when you re-connect.

This is useful for example when you want to work on the same "desktop" from different locations, and it can be used to run a desktop environment on a server that you don't have physical access to or doesn't have a terminal attached (monitor and keyboard). All you need is a network connection.

How Virtual Network Computing Works

So how does it work? You need to install "nvcserver" on the server machine (if not already installed) and "nvcviewer" and client machine (see realVNC for a popular version the VNC software). In order to avoid firewall issues, it is a good idea to use the secure shell ssh to connect from your "viewer" machine to the server on which you want to run the desktop session. The PuTTY package works great for this purpose.

So the first step is to launch an ssh using for example PuTTY. Then you log in to the server and enter:

vncserver
New 'server1.org1.com:6" (juser)' desktop is server1.org1.com.6

Before running "vncserver" you should set up the initialization file "xstartup" in the ".vnc" directory, which should be created in your home directory. This file contains initialization commands, such as

# Execute common xstartup file 
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
# Load .Xresources file
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
# Run the vncconfig helper to enable clipboard transfers and control of the desktop
vncconfig -iconic &
# Launch a GNOME desktop
exec gnome-session &

Now a "desktop" is running on the server waiting to be displayed on your local computer. How do you connect to it? If you installed the realVNC software or downloaded a VNC viewer you run this viewer and enter the server and display number as illustrated in this example:

server1.org1.com:6

The viewer software will also ask you for password. The first time you use VNC on this server you enter a new password, which will be saved in the .vnc folder. The password is for VNC connections and not related to you user account on the server. After a period of inactivity you may be asked to enter your account password as well to authorize the server access.

Once the password is accepted the desktop window should appear with all the specified graphical user interface elements. You can disconnect from the desktop by closing the desktop window.

You can terminate the VNC server process (the "desktop") by entering the following command in a shell window on the server:

vncserver -kill :

For example:

vncserver -kill :6 
export geometry=1920x1058

Where "1920" represents the desired width and "1058" the desired height of the desktop window. It is best to make it match the actual resolution of your screen.