Wednesday, February 17, 2010

Remote Desktop in Ubuntu with VNC and XDMCP

There are lots of links on the Internet that lay out how to set up VNC and XDMCP to enable remote logins for Ubuntu, but most are broken as of 9.04 (Jaunty) and later releases. The issue seems to be the interaction between GDM and the IPv6 stack. In releases before Jaunty, IPv6 support was included as a kernel module. As of Jaunty, support for IPv6 is compiled into the kernel. The good news is that if you don't need IPv6 support today, you can still turn it off and enjoy a remote desktop capability. Hopefully someone will fix GDM before IPv6 really becomes a necessity.

The full procedure for setting up Ubuntu for remote desktop is as follows...

1. Download and install vnc4server and xinetd:

greg@neo:~$ sudo apt-get install vnc4server xinetd

2. Create an entry in /etc/xinetd.d to enable Xvnc:

greg@neo:~$ sudo vi /etc/xinetd.d/Xvnc

Paste the following text to the file:

service Xvnc
{
    type = UNLISTED
    disable = no
    socket_type = stream
    protocol = tcp
    wait = no
    user = nobody
    server = /usr/bin/Xvnc
    server_args = -inetd -once -query 127.0.0.1 -SecurityTypes=none -geometry 1280x800 -depth 24 -extension XFIXES
    port = 5901
}


Note that everything from "server_args =" to "XFIXES" must be on a single line. Also, adjust the -geometry and -depth settings to suit your needs. Settings of "-geometry 1024x768 -depth 16" are probably plenty good for most.

3. Now enable remote logins via XDMCP. From the GNOME desktop, choose System --> Administration --> Login Window. When the preference pane opens, select the Remote Login tab and set Style: to "Same as local".

4. Before closing the Login Window preference pane, click on the Configure XDMCP... button in the bottom right corner. This will open another preference window. In the XDMCP preference window, make sure the "Honor indirect requests" option is unchecked.

5. Close out the XDMCP and Login Window preferences, and move back to the terminal window. Now edit /etc/gdm/gdm.conf-custom and add the following statements:

Under [daemon] add the statement RemoteGreeter=/usr/lib/gdm/gdmgreeter
Under [security] add the statement AllowRemoteRoot=false
Under [xdmcp] add the statements Enable=true and HonorIndirect=false

Some of these may already exist. If they do, and they are correct, then just add any statements that are missing.

6. Now it's time to turn off IPv6 support. I have seen many Google hits on how to do this, and most of them do not work in Jaunty or Karmic. The only one I have found to work is to disable IPv6 support from GRUB. Open up the GRUB menu:

greg@neo:~$ sudo vi /boot/grub/menu.lst

and find the kernel options. You should see one or more entries that start with "title" and include a "kernel" entry a couple of lines down. The kernel entry is typically pretty long -- more than an 80 character screen wide. Add the statement ipv6.disable=1 to the end of the kernel line (or lines, to be safe) and save the changes.

[Edit:  Note that "old" kernels won't understand the ipv6.disable=1 directive and will complain about an unknown option when booting.  Be sure to update your kernel through apt or synaptic to ensure this will work.]

[Edit #2:  Going straight to the config lines at the end of the file may not be the best way to go, as these lines can be overwritten by update-grub.  A better solution is to find the "default kernel options" section and add it there.  Look for the line # kopt=root=UUID=xxxx and just append ipv6.disable=1 to the end of it.  And don't worry that the line appears to be commented out.  Your change will be picked up when you run the command update-grub from the command line.]

7. Reboot the box. When it's back up and running, you can try to connect from a VNC client.