Setup x11vnc server with systemd auto start up

The reason I use x11vnc is that it connects to the existing graphical session. Most other vnc servers will spawn an entirely new graphical session. While that is super cool, I don’t want that feature. This is for remote support, where I want the user and the supporter to share the same session. I use the ‘-auth guess’ to have x11vnc guess the XAUTHORITY file‐name and use it appropriately. This avoids the annoying hard coding of gdm, lightdm, xdm or specific users .Xauthority.

Install x11vnc
# apt-get install x11vnc

The following should work for any distro that uses systemd, just the apt bits are Debian specific.

Generate the password and store it under etc so no users can change this password, only root. You can do this under your users home so that its not managed by root. In my case I didn’t want the user to be able to change or accidentally delete the password.
# x11vnc -storepasswd /etc/x11vnc.pwd

edit (create new) the following file
use whatever text editor you prefer, here I use vi
# vi /etc/systemd/system/x11vnc.service

And add the following, making any changes you want to the x11vnc ExecStart
See the man page for explanations of the switches

[Unit]
Description=Start x11vnc at startup.
After=multi-user.target

[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /etc/x11vnc.pwd -rfbport 5900 -shared -o /var/log/x11vnc.log

[Install]
WantedBy=multi-user.target

Now enable the above, start it and verify its running and listening properly
# systemctl enable x11vnc
# systemctl start x11vnc
# netstat -pat
tcp 0 0 0.0.0.0:5900 0.0.0.0:* LISTEN 2806/x11vnc

Now that the server is all setup lets move onto the client
apt-get install tigervnc-viewer
vncviewer [remote host ip or hostname]

done;


Comments

17 responses to “Setup x11vnc server with systemd auto start up”

  1. Michael Kube Avatar
    Michael Kube

    best explanation and fastest install to install an x11vncserver under Debian

    Michael ,

  2. Question: do I need a network.target in the After=

    like this, After=multi-user.target network.target

    thx

  3. Hi pavlos
    You won’t need the network.target because vnc can run without the network being up. It listens on any interface so you can bring up the network any time and it will be listening and ready for connections.

  4. Prepman Avatar
    Prepman

    spot on!

  5. Awesome. Thanks for sharing this.

  6. By far the best explanation and working guide. This one actually works at boot instead of at login. It also doesn’t shutdown after 1st login like another I had tried with the same -forever in the line.

    Thank you, Sir!

  7. make sure you use lightdm and not gdm3 for display(xauth will fail)and netstat -pat will not show x11vnc service even if systemctl will report the service up and running.

  8. Thank you! I got it work fine so fast with this explanation.

  9. Thank you so much!

    Perfect!

  10. Flint Ironstag Avatar
    Flint Ironstag

    Excellent write-up on this process. Succinct and to the point.

  11. Trying to follow these instructions on a Debian 11 install and running into the following issue:

    systemctl start x11vnc results in
    Failed to start x11vnc.service: Unit x11vnc.service has a bad unit file setting.
    See system logs and ‘systemctl status x11vnc.service’ for details.

    Running systemctl status x11vnc.service results in

    Warning: The unit file, source configuration file or drop-ins of x11vnc.service changed on disk. R>
    ● x11vnc.service – Start x11vnc at startup.
    Loaded: bad-setting (Reason: Unit x11vnc.service has a bad unit file setting.)
    Active: inactive (dead)

    I created x11vnc.service using direct copy paste so I’m not sure whats happening or what I have done wrong.

    Any pointer greatly appreciated.

  12. a Duck It search of “unit .service has a bad unit file setting” had this at the top https://unix.stackexchange.com/questions/642828/why-does-this-systemd-unit-file-generate-an-error-service-has-a-bad-unit-file-s
    do you have spaces around the =?

  13. This works great but tightvnc viewer from my Windows laptop is extremely sluggish. Any ideas on how to speed up?

  14. Thanks Jason, The explanation was spot on. Worked on Mint 21.1 after firewall updates perfectly. I used TigerVNC viewer for the client. I appreciate the help.

  15. I have been trying to get this working for a while now. I ran through the process and all looked good. After a reboot though I don’t see the service listening on port 5900. I try to manually start the service with systemctl and get no errors, but it is still not listening.
    I check the log and I just see the x11vnc service loop, then waiting, then sleep, repeat
    I have confirmed I am using X11 not Wayland.
    I am running Kubuntu 23.10

    Any suggestions?

  16. Glenn

    sorry for the late response, I get a lot of spam in the comments :-/
    what does “systemctl status x11vnc” output?
    it should say Active: active (running)
    maybe share the text from your log.

  17. ari tafari Avatar
    ari tafari

    Clear and straightforward instructions. Thank you

Leave a Reply

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