I’m a Ubuntu fan. And they’ve made it really easy to use VNC (the Linux equivalent of remote desktop) just by choosing System -> Preferences -> Remote Desktop. What’s not so easy, however, is when you have a server or desktop that requires X but you don’t have a monitor plugged in to the machine. If you try to VNC into a machine like that, you’ll get the dreaded “Connection Refused” message. If that machine is remote, it can be a real drag. Here’s how I get around it.
Instead of using Vino, the default VNC server, instead install vnc4server:
sudo apt-get install vnc4server
Then turn on the new VNC server so that it creates the default files it needs:
vncserver :1 -geometry 1280x1024 -depth 16
In theory you could have five or more VNC servers all running different desktops. The :1is the enumerator for this VNC session. The geometry setting allows you to set the resolution you want to have available in the VNC session and the depth setting corresponds to color depth.
You’ll be prompted for a password when you first start it… Enter it twice. The vnc server now creates a default configuration file and starts serving remote connections. You can now connect to the server’s X without having a monitor plugged into it by typing:
vncviewer hostname:1
where hostname is the name or IP address of the server to which you’re trying to connect. You won’t be prompted for a password in future sessions for the :1 instance — it only asks you for a password the first time you start the server instance. To change the password later, use the vncpasswd command.
Note that when you use vncviewer, you won’t be seeing your default Gnome desktop — it’ll be just a blank canvas with an open terminal. To have it display your current Gnome desktop, first kill the current vncserver:
vncserver -kill :1
When it first started, the vnc server should have created a file called .vnc/xstartup in the home directory of the user who started it. Now edit that file and append the following to the end of it:
gnome-session&
Keep in mind that the machine’s X server must be logged into the user’s desktop before any of this will work. You can either have the machine log in to the desktop automatically without requiring a password or you’ll have to be clever about how to enter the Gnome Desktop. Check out my next installment for how to manage the Gnome Desktop from the command line so that you don’t have to allow for automatic logins in order to use VNC.

June 11th, 2010 at 2:19 pm
[...] We talked last week about how to use VNC with a server that doesn’t have a monitor connected to it. [...]