How to setup x11vnc to access with graphical login screen?

  • I have a server running Ubuntu 12.10 and need to be able to remote to this server without being logged-in.

    I have found many solutions, but none seem to work with 12.10.

    Can anyone give me step-by-step instructions on how to configure x11vnc to start as a service (prior to user login) so that when connecting with VNC I will be presented with a graphical login screen?

    I'm new to Linux so please give as much detail as possible in your responses/comments.


    The amount of all these commands and configurations that an average user needs to do just to connect to a remote computer's screen is just ridiculous. On Windows, it just works... with a few mouse clicks, although remote desktop feature only works on expensive editions. I have spent a few hours, and I still could not make VNC start automatically. This is why Linux will remain unpopular OS for average users... (Please do not point things like "Linux is used in Android!" or something. Words have different meanings in different context. You know what "Linux" I mean in this context.)

  • The above answers solve the problem, though a couple of amendments for versions of Ubuntu with systemd (15.04+), as follows:

    • Take advantage of new -auth guess functionality in x11vnc - which helps!
    • Update for systemd (not upstart)

    Run the following to install:

    sudo apt-get install x11vnc
    sudo x11vnc -storepasswd yourVNCpasswordHERE /etc/x11vnc.pass
    # for Ubuntu 15.04+
    sudo nano /lib/systemd/system/x11vnc.service
    # for Ubuntu 16.10+
    sudo nano /etc/systemd/system/x11vnc.service

    Insert this into the file:

    ExecStart=/usr/bin/x11vnc -xkb -noxrecord -noxfixes -noxdamage -display :0 -auth guess -rfbauth /etc/x11vnc.pass
    ExecStop=/usr/bin/killall x11vnc

    Then, start with:

    sudo systemctl daemon-reload
    sudo systemctl start x11vnc

    And ensure the service starts on boot:

    sudo systemctl enable x11vnc

    Referenced for some advice on Requires/Afters params

    why isn't this answer marked as the correct answer?

    The OP needs to do so - and this was answered quite some time after his answer. I appreciate the vote of confidence though - thanks :)

    If there is no display at all, then one may want to set arbitrary resolution: `sudo xrandr --fb 1920x1080`.

    It is not a given the x11vnc will work immediately. It would be a good idea to provide a testing command before commiting to a service that restarts on failure every 2 seconds. I'm using lightdm and xfce4 on a headless cloud Ubuntu 17.10 server. `Restart-sec` should be `RestartSec`

    Got it to work by creating a virtual monitor on the graphics card and switching from gnome3 to xfce4.

    Ubuntu 18.04 also seems to want `RestartSec` rather than `Restart-sec`.

  • Install x11vnc:

    sudo apt-get install x11vnc

    Create a password for your user:

    x11vnc -storepasswd

    If you have ssh setup you can use it to start x11vnc assuming you are logged in already, but remember to tell it to use your password file:

    x11vnc -usepw

    If you are not logged in you will get an error with the explanation:

    If NO ONE is logged into an X session yet, but there is a greeter login
    program like "gdm", "kdm", "xdm", or "dtlogin" running, you will need
    to find and use the raw display manager MIT-MAGIC-COOKIE file.
    Some examples for various display managers:
     gdm:     -auth /var/gdm/:0.Xauth
              -auth /var/lib/gdm/:0.Xauth
     kdm:     -auth /var/lib/kdm/A:0-crWk72
              -auth /var/run/xauth/A:0-crWk72
     xdm:     -auth /var/lib/xdm/authdir/authfiles/A:0-XQvaJk
     dtlogin: -auth /var/dt/A:0-UgaaXa

    Assuming you are using lightdm for the login you can fix this problem you can start x11vnc with the command:

    sudo x11vnc -xkb -noxrecord -noxfixes -noxdamage -display :0 -auth /var/run/lightdm/root/:0 -usepw

    I am not sure this is the best idea to run x11vnc as root. Maybe someone could edit with a way to access the login without using sudo.

    Once this is running you should be able to connect using a vnc client such as krdc (for KDE). You might want to use GNU Screen to keep x11vnc running without needing the ssh session open

    I was able to figure this out using

    Here is a sample upstart job you can use to make it run at startup. It needs to be put in /etc/init/x11vnc.conf. (Note that newer versions of Ubuntu use systemd so see the other answer that has a sample systemd config):

    # description "start and stop x11vnc"
    description "x11vnc"
    start on runlevel [2345]
    stop on runlevel [^2345]
    console log
    #chdir /home/
    #setuid 1000
    #setgid 1000
    respawn limit 20 5
    exec x11vnc -xkb -noxrecord -noxfixes -noxdamage -display :0 -auth /var/run/lightdm/root/:0 -usepw

    Once you have made this file you can start it by running: sudo start x11vnc You can check the log at: /var/log/upstart/x11vnc.log

    You can run `x11vnc` as a normal user, no problem. For example: ssh to the host and run `x11vnc -safer -forever -display :0 2>&1 &` in a tmux session (good practice), it'll run under `$USER`.

    This doesn't explain how to have it auto start as requested (and is a common requirement for such a feature)

    @LovesTha I second that. I've been trying to get `x11vnc` to autostart, but nothing I've tried works. Have you had any luck with this?

    I did, but I can't remember how and I've blown away the config I had it working on.

    See here for a full list of x11vnc options. It took me a long time to find this:

    And see here for an excellent tutorial on setting this up on a Raspberry Pi with auto-start at boot:

    `sudo start x11vnc` -> `start command not found`.

    "start" went away with upstart. Take a look at the systemd config in babelmonk's answer if you are trying to run it at startup on newer versions of ubuntu.

  • Here's how:

    1. Install the X11VNC server (or through Ubuntu Software Center -> X11VNC Server)

      sudo apt-get install x11vnc
    2. Create a VNC password file.

      sudo x11vnc -storepasswd yourVNCpasswordHERE /etc/x11vnc.pass
    3. Create a job file in the editor nano (or gedit, leafpad etc.).

      sudo nano /etc/init/x11vnc.conf
    4. Paste this into the file:

      start on login-session-start
      /usr/bin/x11vnc -xkb -forever -auth /var/run/lightdm/root/:0 -display :0 -rfbauth /etc/x11vnc.pass -rfbport 5900 -bg -o /var/log/x11vnc.log
      end script
    5. Save the file. You created a job for the Upstart event login-session-start.

    6. Restart Ubuntu.

    That's it! You should now be able to connect with any VNC client even before login.

    But how do you get it to work when lightdm doesn't create the auth file till a monitor is connected?

    @didibus I've been trying to do this in Lubuntu, but `x11vnc` fails to autostart every time. It won't even start as a service, for that matter. File syntax is correct and I can start `x11vnc` from the shell just fine. What am I missing?

    This works on Lubuntu too. Specifically, LeMaker's version of Lubuntu for the Banana Pi.

  • babelmonks answer as a bash script, copy and save as & run with sudo bash /path/to/file/ (sorry dont have enough rep to post a comment)

    #install x11vnc & set password
    apt-get install x11vnc -y
    x11vnc -storepasswd 123456 /etc/x11vnc.pass
    #create config file for  system service
    cat > /lib/systemd/system/x11vnc.service <<-EOF
     ExecStart=/usr/bin/x11vnc -xkb -noxrecord -noxfixes -noxdamage -display :0 -auth guess -rfbauth /etc/x11vnc.pass
    ExecStop=/usr/bin/killall x11vnc
    #restart new services &  enable on boot
    systemctl daemon-reload
    systemctl start x11vnc
    systemctl enable x11vnc

    If you want to improve another answer, please suggest an edit to it and don't create a new answer.

    Will happily add this to mine if you'd like to create an edit @nix-badweasel

  • Use my script for easy set up:


    chmod +x ./; sudo ./
  • Here is a config works for sddm (for KDE 5). Currently, -auth guess does not work for sddm, the auth file is different every time, so we need something like -auth /var/run/sddm/*. The service looks like,

    ExecStart=/bin/sh -c "/usr/bin/x11vnc -xkb -noxrecord -display :0 -auth /var/run/sddm/* -rfbauth /etc/x11vnc.pass"
    ExecStop=/usr/bin/killall x11vnc

    I have to put it after, if after display-manager.service, x11vnc cannot find auth file, maybe sddm generates auth file later. This is tested on Manjaro 18.

  • I use my own shell:

    start on login-session-start
    sudo /usr/bin/x11vnc -xkb -auth /var/run/lightdm/root/:0 -noxrecord -noxfixes -noxdamage -rfbauth /var/srv/x11vnc/x11vnc.pass -forever -bg -rfbport <your_port> -o /var/srv/x11vnc/x11vnc.log
    end script

    into the file:


    It makes it auto-start on boot, even on the logon screen it asks for a password.

  • Install x11vnc package

    #sudo apt-get install x11vnc

    Then set the password

    #x11vnc -usepw

    Then create startup script for x11vnc

    #sudo nano /etc/

    In File:

    /usr/bin/x11vnc -bg -forever -shared -reopen -usepw

    Then save

    #sudo chmod 777 /etc/

    Then add the script file to Control Center=>Startup Application Then Click Add

    > Name-----------x11vnc

    > Command-----<map the script file

    > Comment------service

    This is must be required to add for all user

    This will run after user login only

  • If you are working with Ubuntu 19.04, you can check it out with my answer as I figured it out.

    babelmonk's answer almost solves my problem. But I got a problem with display manager ( to deal with login page). I'm using Ubuntu 19.04 in which gdm3 is used. And yet, even with 'smart' -guess parameter from x11vnc, I couldn't connect to my Ubuntu. Thus, I changed it to lightdm which works well.

    You can change your display manager in this command:

    sudo dpkg-reconfigure gdm3

    BTW, if you wanna full steps to configure x11vnc, I wrote a full instruction.

License under CC-BY-SA with attribution

Content dated before 6/26/2020 9:53 AM