Ubuntu 14.10 – Configure your sytem to have x11vnc running at startup

X11VNC

Important Note :

If you need to perform the same configuration on Ubuntu 15.04, you would follow the following instructions  Ubuntu 15.04 – Configure your system to have x11vnc running at startup.  The post hereafter applies to Ubuntu systems  where the Upstart component is used.  Since Ubuntu 15.04, Upstart has been replaced by systemd component

 

Hello World,

Today we will speak about Remote connection to an Ubuntu machine (or more generically a Linux Machine).  Normally, we tend to use the xrdp solution to connect to a remote Ubuntu machine.  Now, we had a request to have remote access configured on a Ubuntu Machine but using vnc technology.

As long as the machine is up and running and that a user is logged into the machine, vnc technology can be used to share and access the desktop remotely.   We have been tasked to configure the Ubuntu machine in a way to ensure that the vnc server would start at boot time.

 We didn’t invent anything here.   We have used the information found on the web (see references and sources sections).

Reference and Sources

 

In this post, we will describe how we did it and see if this is working between multiple reboot.  At the end of this post, you should be able to connect via vnc to your Ubuntu machine even if there is a reboot and even if no user are logged into the machine.  This configuration should display the login screen via vnc viewer client you are using

Let’s Go !

Installing x11vnc server

If you follow us, you know that we tend to use x11vnc software to provide vnc capabilities. For this post and this configuration, we will be installing the x11vnc server.

The installation process is quite straight forward.  Log into your ubuntu 14.10 machine, open the terminal console and issue the following command :

sudo apt-get install x11vnc

 

Click on Picture for Better Resolution

 

To have a minimum of security, we will protect the vnc connection via a password.  The password will be stored in a file.  To create this file, you will need to issue the following command

sudo x11vnc storepasswd /etc/x11vnc.pass

You will be asked to enter a password. Enter the password and confirm your choice and you should be good to go

Click on Picture for Better Resolution

 

Create the Startup Script

So far, we have just issued standard command related to the x11vnc package.  We need to make the x11vnc service starting at boot time.  To to this, we will create the following script  (info found at http://seb.so/vnc-from-boot-without-logging-in-ubuntu-lubuntu-xubuntu-and-mint-lmde/)

/etc/init/x11vnc.conf :

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

Once this is done, you can simply reboot your machine.  You should be able to connect to your Ubuntu machine using vnc viewer client.

Note :

in the script,  The line starting with /usr/bin/… should one line. For presentation reasons, the line has been break into multiple lines.

Test your configuration

To check that you can indeed perform a vnc connection to your Ubuntu Machine, you will try to connect to it using your favourite vncviewer (we are using TigerVnc) while nobody is connected and just after a reboot of the machine.

In the vncviewer, you will provide the ip address or hostname of the machine to connect and the port to be used.  In our example, he port used is 5900.  If you have set a password to protect your vnc connection, you will be prompted for a password as well.

Click on Picture for Better Resolution

 

If everything is ok, you should see the Ubutun login page displayed inside your vncviewer

Click on Picture for Better Resolution

After login into your machine via vncviewer, you should be able to connect to your Unity Desktop and start working on it.  Here because we are connecting directly to the console, we do not need to install any alternative desktop as this would be the case with xrdp software

Click on Picture for Better Resolution

And Voila !  Now you should be able to login to your Ubuntu machine remotely using the VNC protocol and using your preferred vnc viewer client.  This is cool but you might have some drawback or limitation using this method.

The drawback of this method is that whatever you type on your vnc viewer session could be viewed by a user located in front of the computer you are remotely connected to.  Actually, this should be a minor problem given that a lot of machine are virtualized and you do not have a screen in front of each machine nowadays.

The other problem using this method to remotely connect to your Ubuntu machine is the fact that you have to install a vncviewer on all your machines where such remote access is needed.  However, if you are creative you could quickly overcome this limitation (using a web based vnc browser or publish the application on your Remote Desktop Session server as a remoteapp application)

Finally, security wise it seems  that vnc should not be used on internet and should be recommended on your intranet infrastructure. This limitation might be overcome by using encrypted sessions.

Final Notes

In this post, we have seen how we could configure vnc server (i.e. x11vnc) to boot at startup and allow users to connect to the remote machine even if nobody is logged into the machine.  The main drawback we see with this method is that you have to install everywhere the vnc viewer client. At least this would be the standard approach within most organization.  However, there are plenty of other options.  We could install the client as a remoteApp published application and you would not need to have the software installed locally. You could also use a web based vnc viewer.

In the coming posts, we might investigate the web based vnc viewer solution

Stay tuned

Till next time

34 thoughts on “Ubuntu 14.10 – Configure your sytem to have x11vnc running at startup

  1. Thanks for your post. But I tested in ubuntu 14.10, it seems like doesnot work. X11vnc did start when reboot but I tried TigerVNC client and real VNC client from window 7, still cannot connect. I can ping the ubuntu from window w/o problem.

  2. Hello Amber,

    last time we have tried..It was working..We will test again…
    When you say it’s not working…can you provide a little bit more details…Do you see the xrdp login screen ?
    do you have a grey desktop ? Do you have an error message ?

    Have you installed vnc4server even if you are using x11vnc server ?

    waiting for some info (and we will test procedure again to be sure that nothing has changed 🙂 )

    Till next time
    See ya

  3. Hello Amber,

    We had enough time to test the procedure again…and it works for us…
    In the xrdp login screen, please ensure that you have selected the option Sesman-Xvnc
    At the first connection, it might fail. Successive connections are just fine…

    Xrdp on Ubuntu 14.10 with the latest updates

    Hope this help

    Till next time
    See ya

  4. I have already make it work. but if we start fresh default ubuntu install, it won’t work. I have to install ubuntu restricted extras, then it will work. don’t really know which package we installed in extras make it work. Pretty much, I did the following step before i install x11vnc.

    sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade
    sudo apt-get install ubuntu-restricted-extras

    by the way, I did not install xrdp package. Thanks for your reply and you site did help me a lot!

  5. by the way, previously it did not work, the error message is timeout connection error. Could not connect to server at all.

  6. Hello Amber,

    Sorry I was mixing two posts when I replied to you. You do not need to have the xrdp package….

    Can you check your log files on the xubuntu and see if you can get more info about that….
    I would also ensure that you are using the correct port (5900) when you perform the connection. I would check that the port 5900 is open (from a command prompt/terminal session, telnet 5900. If you are blocked at that level, there is already a configuration issue (or firewall issue…)

    You should have a error number when you see the message connection timeout (xxxx)….what’s this number ?

    I’m rather busy right now…but If I have some time, I will redo the setup and send you some additional screenshots – just to ensure that everything looks the same configuration wise – (give me 2/3 days to work on this)

    Hope this help
    Till next time

  7. Hello Amber,

    We have perform the test again. We have performed a fresh install of ubuntu 14.10, followed the described procedure and worked immediately…

    This should be working for you as well. You can check the log file created in /var/log/x11vnc.log to have more insight about the problem
    Your problem seems related to a firewall or maybe you have changed settings on the tiger vnc viewer ???
    If possible, try from a machine located on the same subnet as the server you are trying to reach, and test if connection goes through.
    If this is working, everything is configured as it should. If this is not working, check the local firewall on the ubuntu server and check your settings on your client as well – port 5900 might be blocked

    Keep us informed about your progress … – ) and do not hesitate to contact us for more info or ideas to help you out

    Hope this help
    Till next time
    See ya

  8. Hi there! everything work like a charm with an internal IP.
    If I try to connect from another network (through the internet IP of the host), it doesn’t connect, it works if I use VCN but I have to log in first, because I couldn’t configure it to start at boot.

    Thanks

  9. Hello,

    Thank You for suggestion .

    I have created x11vnc.conf in /etc/init/x11vnc.conf :

    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

    It is working on startup but some issue with that.

    When i close connection from vnc client without login in ubuntu desktop , then x11vnc service stop automatically. I have to start every time .

    Do you have any solution for this ?

  10. Since my update to 15.04 this doesn’t work any more. Even if I try the whole procedure all over again.
    Any thoughts?

  11. Hello There,

    This might be due to the fact that the service manager has been changed in Ubuntu 15.04…..
    Since this version upstart solution is not used anymore and has been replaced by systemd….

    I will need to check/test/validate and re-write this post to see if we can achieve the same results when using systemd service manager solution

    Hope this help
    Till next time
    See ya

  12. Excellent guide, works perfectly. I use Duck Dns to get the IP manually to be able to log in from anywhere over the internet but because my old router doesn’t allow me to have a duck dns entry I have to log in manually to duckdns and get it manually no big deal really.

  13. This largely works, except when I connect to this session (using either JumpDesktop or Apple ScreenSharing, the different layers in the desktop appear to be stacked vertically, like in this screen shot: http://imgur.com/8KuHzLa

    Any hints?

  14. Hello Greg,

    We never tried to use this from a Mac computers….So far, we have no idea what that could be….
    but might be interesting to see how we can fix this…… asap we have time, we will try to have a look at it

    till next time
    see ya

  15. This worked perfectly mostly. It runs on startup and I’m able to connect via Tight VNC. The problem I’m having is that -forever doesn’t work. When I close the connection x11vnc closes. I’ve tried -many and -loopbg as well and neither of them work either. Any ideas?

  16. Amazing what happens when you actually read everything properly. Went back to double check everything and see if I could solve the problem. Apparently I missed the note that said everything had to be on one line. You would think that I would have figured it out when it didn’t ask me for the password, but I didn’t even notice. Everything awesome thanks for the tutorial.

  17. Thanks for this, its working, however service x11vnc restart returns:

    stop: Unknown instance:
    x11vnc start/running, process 25307

    and the process is not restarted.
    Ubuntu 14.04.3 LTS

  18. Found in comments to http://seb.so/vnc-from-boot-without-logging-in-ubuntu-lubuntu-xubuntu-and-mint-lmde/

    add respawn after start line, remove -bg option on x11vnc commandline

    I’m now using:

    start on login-session-start
    respawn
    script
    /usr/bin/x11vnc -xkb -repeat -noxrecord -noxfixes -noxdamage -forever -auth /var/run/lightdm/root/:0 -display :0 -rfbauth /etc/vncpasswd -rfbport 5900 -o /var/log/x11vnc.log
    end script

    service x11vnc start|restart|stop|status works correctly now.
    Ubuntu 14.04.3 LTS

  19. Good night.
    I am new to linux so, can you tell me how to create the scritp?
    Went to the init folder but i canot create a file there. Typedthe commands on terminal and nothing.

    Google a lot but they all say how to write it but no tutorial on how to put it where you want and so on.

    thanks for any help here.

  20. Hello Peter,

    2 options :

    A. if you want to do it through the GUI, open terminal and type sudo nautilus > then browse to /etc/init and then create the X11vnc.conf file and copy/paste the info as described in the post

    B. if you want to use the command prompt only, open terminal
    type sudo nano /etc/init/x11vnc.conf
    in the terminal session type the info as described in the post to have the same content

    hope this help
    Till next time
    See ya

  21. Hello Griffon,

    Thank you for the wonderful tutorial. I have just one issue.
    I have to add -xkb argument since I connect from A Win machine and Shift key does not work. However when I add -xrb to the etc/init/X11vnc.conf file, I don’t see -xkb into the Task Manager after reboot. Moreover, it seems that the script is not being read at all, since I changed port to 5901 and it was not reflected after a reboot?!
    I also checked the .x11vncrc file, -xrb is uncommented. Could you please suggest a way to check from where x11vnc is loading its config on startup? Or which script starts a given process st all?
    Thank you in advance for your time.

  22. Hello Hristian,

    For the Keyboard issue, you can try the following workaround… If you are using TigerVNC as VNC client, and if you need to have Caps lock (this is the switch key) enabled in your VNC Session, you move the mouse outside the vnc client, you click on your Windows desktop and you press the Shift key or Caps lock key. If you go back to your VNC Session, you should see that the Shift key is enabled in your VNC Session

    Updated about keyboard issue : you can try to append at the end of the command -capslock (in the /lib/systemd/system/x11vnc.service). Restart the service and you should be able to use the Caps lock (or Shift button). Please restart the x11vnc service to be sure that changes are applied.Final note : To have it working, the state of the keyboard should be same on windows and linux via vnc…

    Hope this help
    Till next time
    See ya

  23. Hello again,

    Thank you for the prompt reply.
    The “server” (an ordinary box) is actually in a room next to mine. I am using TigerVNC, there is lag with Ultra and Real VNC. The two keyboards are in one and the same state – Caps Lock is off. However I have tried enabling Caps Lock on both and on only one of the keyboards. No difference. I then added -capslock to “/lib/systemd/system/x11vnc.service” – this is the file from which x11vnc reads the arguments on startup. I see in Task Manager that -capslock is loaded. No difference. Then I added also -xkb switch, again w/o result.
    I did full restart between the changes, Windows habit.
    Using Caps Lock is not a great issue, but I sometimes need the special characters. And I do not like much the idea of using the ASCII codes.
    If you have the time and interest, it is fine for me to grant a remote session. Please e-mail me, if I am not too cheeky. 🙂

    Best regards,

    Hristian

  24. Addition: The Shift key actually works for some keys, but not for the letters. Working f. ex. – 9-( , 0-) , 5-% , 4-_ (instead of 4-$) , 3 not working…

  25. Addition: All is working fine now. It appears that my keyboard layout was with changed order. Instead of US,BG it was BG,US (US at second place, below Bulgarian). Since I didn’t see an option to move US up, I just deleted and readded Bulgarian. Sorry for the trouble.

    Best regards,

    Hristian

  26. Hello Hristian,

    Good to hear that everything is working as expected now…
    thank you for the visit and to provide feedback to us

    Till next time
    See ya

  27. Hi, nice writeup. I’m new to Linux (use Macs currently), and have a machine running Mint. I am wondering if these instructions will work for that as well? I want to move this Mint box I just set up to be headless and will need to have it so that VNC server will be running at all times so I can remote desktop from my Mac to the Linux machine. Thanks.

  28. @AgentPhish,

    It should be working as Mint is a derivative of Ubuntu. However, some people tried and had some difficulties. We would need to test and give it a try
    X11vnc might not be the best choice for Headless systems. You could try to use xrdp software and see if this would be working for you

    At the moment, quite busy with work,projects and travelling to other countries…so might take some time from us if we need to test that….
    Hope this help

    Till next time
    See ya

  29. Thank you very much for this post!
    It helped me a lot.
    I use the vnc connection in local network only to work with a legacy scanner which will not connect to my actual linux. So security issues are of no interest for me.

    Kind regards, Nils

  30. a big Thank for your post Griffon

    After having struggle for 3 days you finally saved me … linux is new for me

    My question is : In the case the VNC connection is not established during the very first minute after a boot (or a reboot) the connection is established but the screen stays black.
    Is there any solution for reseting the display when the vnc connection is established, in order to avoid the mandatory reboot for having an operationnal display ?

  31. @Facel,

    We never faced this kind of issue. We were always able to perform remote connection even if the machine was booted for a long time….
    We will need to investigate this and see if this is indeed a problem or not

    till next time
    See ya

Leave a Reply