In LUbuntu (and Ubuntu and XUbuntu) there are a number of fairly decent VNC servers, broadly split into 2 groups – 1 lot that let you view the existing desktop (i.e. remote control your existing session) and the other lot that create seperate X sessions that only exist under the VNC server. I’m interested in the first lot, and I’d like to be able to login to my X session over VNC before I’ve logged in on the box itself.
A standard package in Ubuntu is the Vino VNC server – it’s the one that’s used when you select “allow users to remotely control my pc” which is quite handy. However, it only lets you log in once your user has logged into Gnome or XFCE (i.e. after you’ve got past the login promt in GDM or LightDM) – so if your PC reboots whilst you’re away, it’s a bit of a pain as you can’t VNC into it.
In XUbuntu 11.10, the team removed GDM (Gnome Display Manager) and replaced it with LightDM (Light Display Manager) so these instructions are specific to that, although they may work on other setups. These instructions also carry over to Ubuntu/LUbuntu (lxde-based) 12.04, and probably 12.10 too as they now all use the same login display manager.
LightDM apparently supports a VNC server out of the box; however, it’s designed to work with tightvncserver (or similar) which create separate X sessions (the 2nd lot of VNC servers I mentioned above) so not quite what we’re after1.
Ubuntu derivatives use Upstart (upstart.ubuntu.com) to manage startup processes – LightDM (and GDM!) creates a
login-session-start event when the display manager is up (i.e. when X is all loaded, but before you’ve logged in) so we’ll create an upstart job that listens for that, and starts a VNC server on the existing X session, allowing connections before login.
Step 1 – we want the VNC server to have a password, just in case – the VNC port shouldn’t really be exposed to the outside world – it’s easy to wrap it in an SSH connection to encrypt everything for you (see here for a good explanation of how to set that up).
sudo x11vnc -storepasswd /etc/x11vnc.pass
This will prompt you for a password to (lightly) secure your VNC server.
Step 2a (for LightDM – XUbuntu, and all Ubuntu variants 12.04 onwards) – create the upstart job. Put this in
start on login-session-start script /usr/bin/x11vnc -xkb -auth /var/run/lightdm/root/:0 -noxrecord -noxfixes -noxdamage -rfbauth /etc/x11vnc.pass -forever -bg -rfbport 5900 -o /var/log/x11vnc.log end script
/var/run/gdm/auth...or something similar, although I haven’t got a box to test it on
Step 2b (for lxdm – LUbuntu) – LXDM doesn’t seem to emit the right event, but instead is has /etc/lxdm/LoginReady which lets you specify pre-login events. However, we need to first get the xauth setup properly. Edit
/etc/lxdm/lxdm.conf and uncomment the line:
This specifies that we’re going to use a different xauth path; we also need to update the /etc/lxdm/LoginReady file with our x11 command, using the updated xauth path.
Put this in
/usr/bin/x11vnc -xkb -auth /tmp/.Xauth1000 -noxrecord -noxfixes -noxdamage -rfbauth /etc/x11vnc.pass -forever -bg -rfbport 5900 -o /var/log/x11vnc.log
Step 2c (for mdm – Mint LMDE)
Mint LMDE (Debian edition) doesn’t use the upstart things; instead, put this at the end of
/usr/bin/x11vnc -xkb -auth /var/lib/mdm/:0.Xauth -noxrecord -noxfixes -noxdamage -rfbauth /etc/x11vnc.pass -forever -bg -rfbport 5900 -o /var/log/x11vnc.log
Note that this uses the auth path for mdm which is
Step 3 – Done!
Reboot! That’s all there is to it – hopefully, you’ll now have a shared VNC server which connects to your main desktop X session, running on port 5900 using the password you gave, all started automatically as soon as LightDM asks you to login. Hooray!
Note for Ubuntu 14.04+ users
The default screen-locker in recent Ubuntu versions is light-locker; this is usually activated when your screensaver kicks in or your desktop is locked. For some reason, this has a bizarre behaviour that replaces the DISPLAY your desktop is running on, and this causes x11vnc to then fail to interact with your active session.
If you’re happy to use xscreensaver instead (which is, in my opinion is just as powerful and secure), then you can use that as a replacement for light-locker, and this doesn’t replace the active DISPLAY, meaning x11vnc continues to work. To do this:
sudo apt-get purge light-locker sudo apt-get install xscreensaver
Then reboot, and no more ridiculous disconnections.
[VNCServer] enabled=true port=5901 # I've used port 5901 so it doesn't interfere with the setup from above
/etc/lightdm/lightdm.conf then reboot – should have a separate X session available for VNC’ing into.