5

I am using Ubuntu 19.04. I want my VNC server on my Ubuntu computer to turn on during boot; I don't have a monitor plugged into it. I want to be able to run the full Ubuntu desktop remotely.

I have managed to get my SSH server to work, and I can also get my x11vnc server to display on my Mac VNC client.

However, this only works if I manually log in to Ubuntu and run the command

x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /home/USERNAME/.vnc/passwd -rfbport 5900 -share

I am able to create an SSH tunnel on my Mac and connect to it using a localhost:5900 connection.

Next, I tried to make x11vnc turn on during boot, so I did the following.

  1. sudo nano /lib/systemd/system/x11vnc.service

  2. I saved the following text (123 is my gdm UID number)

    [Unit]
    Description=Start x11vnc at startup.
    After=multi-user.target
    
    [Service]
    Type=simple
    ExecStart=/usr/bin/x11vnc -loop -forever -bg -rfbport 5900 -xkb -noxrecord -noxfixes -noxdamage -shared -norc -auth /run/user/123/gdm/Xauthority -rfbauth /etc/x11vnc.pass
    
    [Install] 
    WantedBy=multi-user.target
    
  3. I ran the following commands

    sudo systemctl enable x11vnc.service
    sudo systemctl daemon-reload
    sudo systemctl start x11vnc.service
    
  4. I rebooted but didn't log in to my Ubuntu computer.

  5. I connected to SSH and created a tunnel successfully on my Mac.

  6. I tried to connect to the VNC server, but that failed.

  7. I then logged into my Ubuntu computer manually.

  8. I tried to connect to the VNC server, managed to connect, but it was a black screen.

So what I can tell is that the service only started when I log in to the Ubuntu session manually.

Is there a way to do what I am trying to achieve? I am willing to use another server as well; I am only using x11vnc so that I wouldn't have to install a new desktop.

1 Answer 1

2

There are two ways to run a VNC server:

  • run in parallel with the physical console - your VNC sessions are independent, you can't see what the physical console user can see.
  • integrate with the physical console: the display is shared, you can leave the physical seat and connect with VNC to the same session or vice versa.

The physical console is usually protected by xauth. How to integrate the VNC server with it depends on your display manager. I'll use lightdm as an example.

Lightdm creates a file in /run/lightdm/root/ and you can tell x11vnc to use it like this: -display :0 -auth '/run/lightdm/root/:0'

Alternatively, the -findauth option may work for well-known display managers.

So don't try to start a systemd service. First start x11vnc manually with various options and see if you can connect.

Also, don't try to edit /lib/systemd/system/x11vnc.service because it will be overwritten on package update. Create a copy in /etc/systemd/system/ or even better override only the needed settings in /etc/systemd/system/x11vnc.service.d/custom.conf

My working x11vnc.service:

[Unit]
Description=VNC Server for X11
Requires=graphical.target
After=graphical.target

[Service]
ExecStart=/usr/local/bin/x11vnc-lightdm

[Install]
WantedBy=graphical.target

/usr/local/bin/x11vnc-lightdm:

#!/bin/bash
OPTS=
exec /usr/bin/x11vnc \
    $OPTS \
        -rfbauth /root/.vnc/passwd -forever -loop -display :0 -auth '/run/lightdm/root/:0'
3
  • Hi how would you run it in parallel ?
    – anarchy
    Dec 11, 2021 at 8:48
  • @anarchy x11vnc is not suitable for this, you will need tigervnc or something. In traditional setups it can be started by the display manager, see wiki.archlinux.org/title/LightDM#VNC_Server . Sorry, I never used Ubuntu newer than 14x
    – basin
    Dec 11, 2021 at 9:18
  • This answer could get cleaned up a bit, but this worked for me. +1
    – Ben
    Feb 17 at 0:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .