8.15. Using VNC for Remote Linux -to-Linux Administration

You want to use VNC to control other Linux PCs from your Linux box.

Install the VNC server and viewers of your choice on both Linux PCs. In this recipe, we'll use TightVNC. Fire up the VNC server on the first PC. This example shows a first-time startup that creates the server's configuration files and password:

	carla@windbag:~$ tightvncserver
	You will require a password to access your desktops.
	Password:
	Verify:
	New 'X' desktop is windbag:1
	Creating default startup script /home/carla/.vnc/xstartup
	Starting applications specified in /home/carla/.vnc/xstartup
	Log file is /home/carla/.vnc/windbag:1.log

Then, it exits. Start it up again:

	carla@windbag:~$ tightvncserver
	New 'X' desktop is windbag:2
	Starting applications specified in /home/carla/.vnc/xstartup
	Log file is /home/carla/.vnc/windbag:2.log

Notice that it helpfully tells you everything you need to know: the connection parameters, configuration file, and logfile locations.

Now, run over to Linux PC number two, open a VNC viewer, and connect with the hostname:

	windbag:2

Or, use the IP address:

	192.168.1.28:2

It will ask for a password, and there you are.

You can shutdown tightvncserver sessions on the server like this, specifiying the session number:

	$ tightvncserver -kill :2
	Killing Xtightvnc process ID 24306

Note that you must append a session number because Linux supports running multiple VNC servers at the same time.

If you configured the server to use a different port number than the default 5800 (for HTTP) or 5900 (VNC viewer), you'll need to specify the port number in the client, like this for port 6000:

	windbag:6002

VNC adds the session number to the port number, so session 3 is 6003, and so forth.

You'll notice this is quite a bit faster than using VNC to run Windows from Linux. This is because VNC only needs to handle X Windows, which was designed from the start to support networking. So, all VNC needs to do is transmit keyboard and mouse input over TCP/IP, rather than replicating the entire screen like it does with Windows, which uses an entirely different graphical subsystem. In effect, VNC must repeatedly screen scrape and transmit a copy of the Windows display.

You may run as many VNC servers on a single Linux PC as you like. Just open new instances of the VNC server, and it will automatically assign a new display:

	$ tightvncserver
	New 'X' desktop is windbag:3
	Starting applications specified in /home/carla/.vnc/xstartup
	Log file is /home/carla/.vnc/windbag:3.log

You can go nuts and connect back and forth as much as you like, or daisy-chain several VNC sessions by connecting to other PCs from inside the remote sessions.

Run ps ax | grep vnc to see how many servers you have running locally:

	18737 pts/1    S      0:00 Xtightvnc :1 -desktop X -httpd /usr/share/tightvnc-java -
	auth /home/carla/.Xauthority -geometry 1024x768 -depth 24 -rfbwait 120000 -rfbauth /
	home/carla/.vnc/passwd -rfbport 5901 -fp /usr/share/X11/fonts/misc,/usr/share/X11/
	fonts/cyrillic,/usr/share/X11/fonts/100dpi/:unscaled,/usr/share/X11/fonts/75dpi/:
	unscaled,/usr/share/X11/fonts/Type1,/usr/share/X11/fonts/CID,/usr/share/X11/fonts/
	100dpi,/usr/share/X11/fonts/75dpi,/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType,/
	var/lib/defoma/x-ttcidfont-conf.d/dirs/CID -co /usr/X11R6/lib/X11/rgb

	19479 pts/5    S      0:00 Xtightvnc :2 -desktop X -httpd /usr/share/tightvnc-java -
	auth /home/carla/.Xauthority -geometry 1024x768 -depth 24 -rfbwait 120000 -rfbauth /
	home/carla/.vnc/passwd -rfbport 5902 -fp /usr/share/X11/fonts/misc,/usr/share/X11/
	fonts/cyrillic,/usr/share/X11/fonts/100dpi/:unscaled,/usr/share/X11/fonts/75dpi/:
	unscaled,/usr/share/X11/fonts/Type1,/usr/share/X11/fonts/CID,/usr/share/X11/fonts/
	100dpi,/usr/share/X11/fonts/75dpi,/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType,/
	var/lib/defoma/x-ttcidfont-conf.d/dirs/CID -co /usr/X11R6/lib/X11/rgb

Run killall Xtightvnc to stop all of them.

Don't run Xtightvnc directly, because tightvncserver is a wrapper script that performs sanity checks and emits useful error messages.