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.
– 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.
(for LightDM – XUbuntu, and all Ubuntu variants 12.04 onwards) – create the upstart job. Put this in /etc/init/x11vnc.conf :
start on login-session-start
/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
Note: if you’d like this to work with GDM instead, you’ll need to find where GDM puts its MIT-MAGIC-COOKIE – I believe it’s /var/run/gdm/auth... or something similar, although I haven’t got a box to test it on
(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 /etc/lxdm/LoginReady:
/usr/bin/x11vnc -xkb -auth /tmp/.Xauth1000 -noxrecord -noxfixes -noxdamage -rfbauth /etc/x11vnc.pass -forever -bg -rfbport 5900 -o /var/log/x11vnc.log
(for mdm – Mint LMDE)
Mint LMDE (Debian edition) doesn’t use the upstart things; instead, put this at the end of /etc/mdm/Init/Default:
/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 /var/lib/mdm/:0.Xauth
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!
1. If you’d like to have a separated VNC server running too you can – make sure you have tightvncserver installed (or similar) and then put
port=5901 # I've used port 5901 so it doesn't interfere with the setup from above
in your /etc/lightdm/lightdm.conf then reboot – should have a separate X session available for VNC’ing into.
I don't mind you linking to content from my site, but I'd rather you didn't just copy/paste it! Or at least a credit!
Sorry, it might be not noticeable, but the source link was in the end of post.
I'll emphasize it, and also add the reference to the beginning of the post.
Thanks for your article.
Reboot?!?! Is there any way to just _restart_ the service? Having to reboot anytime we make tweaks on Linux is too Microsoft-y.
U can try to just restart lightdm service.