VNC at graphical login for Ubuntu 12.10 or 12.04

It sounds trivial; create an upstart script to start on boot, but this had me googling for a little while.

I used x11vnc as the vnc server. The main issue was that x11vnc needed to bind to an Xauthority file. In order to get it running for graphical login, the Xauthority needed to be for the desktop manager (in this case, lightdm) . It took me a while to find the right location ( ⁄var ⁄run ⁄lightdm ⁄root ⁄); once I had found the answer, the script was easy. I created a file in the upstart init script directory,  ⁄etc⁄init ⁄x11vnc.conf

Lets take a look at what this does; lines 1 and 3 are self explanatory, line 5, ensures that the vnc server is started at the right time (not before lightdm), otherwise the Xauthority file will not exist. Line 6 stops the vnc server on shutdown or reboot.

Lines 8 and 9 ensure that the vnc server is restarted if it fails, but if it respawns x times in y seconds it stops (10 times in 5 seconds in this case). This makes sure it is available but if there is a more serious problem, it stops trying. Line 10 ensures that the process has the correct permissions.

Finally, line 12 starts the x11vnc server. The -forever flag makes sure the server does not exit when a user logs out. The -auth flag is the Xauthority file, which lightdm stores in  ⁄var⁄run⁄lightdm⁄root⁄, usually :0, which indicates the display number lightdm binds to. The -display flag binds to display 0, though it should match the display number used for the Xauthority file. The -rfbauth flag is optional, used only if x11vnc has been configured to use a password file.

Reboot the system, and there it is. Simple but effective.


About Matt

Cloud Systems Engineer at Reed Elsevier; cloud computing advocate, rock climber, swing dancer, amateur photographer, professional idiot....
Bookmark the permalink.

3 Responses to VNC at graphical login for Ubuntu 12.10 or 12.04

  1. JoQ says:

    Thanks, that helped me alot :)

  2. Todd says:

    Thanks for the article! However, I’m running into a problem on my machine. If I include the respawn lines as you suggest above, I find that I will have hundreds of instances of x11vnc running. If I remove those lines, I only have one instance, as expected.

    As a result, I’ve removed the respawn lines and everything works fine, but I’m a bit concerned that if it DOES crash, for whatever reason, it will not be automatically restarted.

    Any idea why it would be spawning so many instances, even though it’s not crashing?

    • Matt says:

      Hi Todd,

      Glad you found the article useful. The respawn problem is a new one on me, difficult to diagnose without seeing your exact script, configuration and system log output. Check your syslog, and set the -o flag for x11vnc to log, there might be some useful information there.

      I recommend posting the question on; more people who can help will see it that way. Make sure you include the script, your x11vnc configuration and any relavent log output. Send me the link and I’ll see if I can help.


Leave a Reply

Your email address will not be published. Required fields are marked *