VNC (Virtual Network Computing) is a graphical desktop sharing program. Have you ever wished you could take your desktop, with all its open windows and running programs, home? Or check on it from home? One solution is to get a laptop that hibernates, but what if you don't want the jobs to quit while you are commuting? In some cases, for example UsingFarm
, you want to keep certain graphical software open indefinitely and would have to sacrifice lots of work if anything (power outage, battery expiring, logout to project slides, etc.) forced you to exit the software. VNC to the rescue.
VNC also makes it easy to run graphical programs on a remote linux server, while logging in from Windows. This is not a problem for linux users, who can just login using ssh -X remote.host
to have graphical programs running on the remote machine open on their local screen.
Linux has various packages for VNC, including TightVNC
, which also runs on Windows. The following assumes that vncserver
is installed on the linux server where you want your desktop to run and vncviewer
is installed on the client, from which you will access the desktop. I also assume that you will want to access a linux desktop, not a Windows desktop, since all of the servers meant for running big jobs in our lab are linux machines.
Keep in mind that VNC is not designed to access the desktop that displays on the monitor directly connected
to a desktop machine (actually, I think it is for Windows). Think of VNC as creating a virtual desktop, floating in space, seen by no one, until the vncviewer connects. Long-running jobs, the ones you want to access from multiple places at multiple times, should be run on that virtual desktop not
the real desktop. The best thing is if you get disconnected, for whatever reason, the desktop will continue to exist and all programs in it will be fine, until you are able to connect again.
Also, multiple virtual desktops can exist simultaneously, each is displayed on what is called a display
, labeled :1, :2, etc. I will assume the display is :n
, and you should replace the n
with your display number wherever it appears below, include in the context 590n
. Finally, I will refer to the remote host running vncserver
There are three steps for getting your virtual desktop running. After you start the server for the first time, you need not start it again, so only steps 2 and 3 are required to reconnect.
01. Starting VNC Server
- Logon (using ssh) to the <remote_host> where you want the desktop to run
- Start the server: vncserver :n -geometry 1600x1200
- The first time you will be asked to setup a password; don't forget it because you will be prompted for it each time you use vncviewer (I think it is OK to leave it blank)
- Please read the introduction above to understand the :n part of the command.
- You should choose a screen geometry appropriate (small enough to fit within) the screen of the client computers that will be accessing it.
- You can see the geometry of your current screen by accessing the Display settings in your operating system's configuration/settings (in Windows, try right-clicking on the desktop, selecting Properties, then Settings).
- If someone else is running vncserver on the display you choose, it will say "A VNC server is already running as :n", and you will need to select another one, say :n+1
- You can now logout at any time, and the desktop will continue to run in virtual space, waiting for a vncviewer connection
02. Tunneling VNC Through SSH
03. Connecting to VNC Server
- Linux Client: assuming some version of vnc is installed and you have started the tunnel as described above, type
- Windows Client:
- Go to RealVNC and download the free edition and follow instructions to install. You only need to install the viewer, unless you'd like to play around with sharing your Windows desktop with other machines. Another options is tightvnc which is totally free. I'm happy with it on linux, but have not tried it in Windows.
- Start vncviewer (double-click) and choose to connect to localhost:1
- Enter your password when prompted (the one you used when first starting vncserver
04. Disconnecting from VNC Server
- Just close the vncviewer window.
- If you are in full screen mode, try Esc or F8 to get out of full screen mode.
05. Quiting VNC Server
- As indicated, you can leave vncserver running indefinitely (until the server reboots).
- However, you can also quit it by issuing the command vncserver -kill :n on the <remote_host>.
0Details: So it doesn't look like your regular desktop?
So, you followed all the instructions above, but the desktop you connect to with vncviewer looks incredibly flimsy and primitive compared to your usual environment. Recreating your usual desktop is the trickiest part of the whole process because it varies so much from computer-to-computer. Here is my best advice.
- On the <remote_host> issue the command ps uaxw | grep ssh-agent and make note of what command the instance owned by you is running (after the -c argument), say gnome-session
- Edit ~/.vnc/xstartup and replace the last line with the same command, backgrounded, e.g. gnome-session & (the & backgrounds it)
- Every time you edit ~/.vnc/xstartup, you should restart vncserver by killing, then starting it as described above.