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.

Instructions

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.

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

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:

xauth_path=/tmp

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.

Note that this uses the auth path for mdm which is /var/lib/mdm/:0.XauthStep 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.

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

[VNCServer]
enabled=true
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.

88 responses to “VNC from boot on Ubuntu 10.04 all the way to 14.04 without logging in, using LightDM (or GDM) and x11vnc (includes LUbuntu with lxdm and Linux Mint LMDE with mdm)”

Thanks for this, worked for me on Xubuntu 12.04 and stayed working after in-place upgrade to 12.10.

I did notice that it seems to disable X auto-repeat while a VNC client is connected, even on the local side. Adding -repeat to the x11vnc line of the script(s) seems to fix it, or you can run ‘xset r on’ in a terminal to enable it on a case-by-case basis.

I’m not yet seeing ill effects from omitting -noxrecord -noxfixes -noxdamage and enabling -repeat with TightVNC 2.6 as the client.

According to the Ubuntu x11vnc man pages (http://manpages.ubuntu.com/manpages/lucid/man1/x11vnc.1.html), versions shipped with 10.04 LTS and newer will wait until a window manager is running before using XFIXES in order to prevent the crash you mention. It therefore seems safe (so far) to omit the option, which is great for me because I prefer to be able to see what the mouse cursor is actually supposed to look like.

Since Xubuntu uses xfwm4 instead of compiz by default, it seems safe to omit -noxdamage.

I have Ubuntu 12.10 running, I have installed x11vnc and I created the /etc/x11.conf file with the script above but how do you get x11vnc to run on startup? When I do a ps -ef | grep x11 it’s not running.

Hi and thanks,
Your script worked for me fantastic until now 🙁
no problems at all until :
I’ve just installed a second vnc server (vnc4server) on 5901
and my problems started with it:
I have no problem with connection to vnc4server at 5901 to separate x session (lxdm) but when I try to connect to x11vnc at 5900 I getting a login screen (lightdm) and after typing my password connection is reset (vnc client exits) and I am back to login screen with next connection try. I have removed vnc4server but problem still exist even after restart, so I cant connect anymore to x11vnc.
I have ubuntu 12.10 minimal with lightdm, lxdm and xbmc
I need both vnc to main and separate x sessions any help please.

This worked great for me (Ubuntu 12.04, using step 2a for the xubuntu/xfcs desktop environment).

After the setup, I had to do one more thing that was not documented here: while in the SSH session where I set all of this up, I ran “initcfg start x11vnc” to start VNC for the first time; now, it appears to reliably survive both reboots and logoffs.

I am running Ubuntu 14.04. I followed all of the steps in this guide, but when I connect it seems like it is in View-Only mode. I am using RealVNC on a Windows 8.1 machine. I have the options selected to allow keyboard and mouse input, but no luck. I can only view the screen. I can’t interact with any windows or type text. Any thoughts?

If you remove the -bg parameter, upstart will track the x11vnc process for you. This allows you to (re)start/stop the x11vnc server via initctl commands (e.g. sudo initctl start/restart/stop x11vnc). It may also be worth putting the respawn keyword after the “start on” line if you’re at all paranoid about x11vnc crashing, as this will direct upstart to relaunch it when it dies.

For Lubuntu 14.04 LTS + LightDM, sometimes this does not work due to the default screen may switch from :0 to :1 or :2 etc and during screen saver / screen lock and for some reason unable to release it.

To kill the wrong screen (cannot login VNC, or after login it is black screen), run below command:

killall lxsession

To check which is active screen (:0 or :1 or :2 etc), run below command:

The issue is actually caused by light-locker which is what the default Ubuntu screensaver uses to lock your screen, and it’s this that does the bizarre DISPLAY replacement. However, I’m more than happy using xscreensaver or i3lock, and they don’t replace the active DISPLAY which means x11vnc continues to work.

[…] is the block-screen: the default package (for this task) has recently changed to light-locker. It turns out that, as a side-effect, light-locker switches current VT to (I guess) VT8 (where default Xorg/X11 […]

Question: What is the correct way to switch users with this method? I noticed that by selecting the setting icon in the top right hand corner of the screen and then selecting one of my other desktop users that i lose connection.

[…] 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. […]

It works!!! I use Lubuntu I could get a x11vnc server working but I had to use autologin…. I upgraded from Lubuntu 11.10 to 14.10 …. my vnc server would just stop after 5 minutes and not do anything…. This just works.

Thanks a lot for this howto! I’m trying to set up kodi at home, and it helps me a lot. The introduction about the 2 groups of VNC server and the instructions for all the different display manager are very usefull. Thanks again.

OMG I have been struggling with vnc issues and xubuntu 14.04 for over a year. Steps 1 and 2a fixed it! I spent so much time googling for answers and never suspected it was a ldm issue. I support 15 xubuntus at our local library and need to get in fast to any machine to give remote help and support. I am still having issues with the ssh tunneling I have to go through a router on the remote end and a forwarded port. I keep getting password failed. I think it is some step required to set a ssh password but can find nothing on that. Thank you so much I hope this stays with updates.

Followed these instructions but I fall at the last hurdle. When I try to connect I get an authentication failure. It is as though I typed the password wrong but I’m definitely using the one I created in the password file.

I’m running Ubuntu 14.04.3 and the only deviation from these instructions have been at the point where I attempted to swap the screensaver with;
sudo apt-get purge light-locker
sudo apt-get install xscreensaver

Both commands failed, the former because it was not installed and the latter because it was already installed.

I’m now scratching my head and any pointers would be much appreciated.

I’m using Ubuntu 14.04.3. I’m getting to Ubuntu desktop login screen (I have multiple users on this server) and after I enter my password the desktop wallpaper comes up for a short time , but then VNC viewer (both TightVNC and RealVNC) return error message “Connection is gracefully closed”. What this could be/
Thanks.