0

I have an X server all configured and running with LightDM and GNOME desktop. I have x11vnc installed to access the X server. I open a terminal in GNOME and run x11vnc. This gives me VNC access to the real X server, however I would like to start it automatically. I could put x11vnc in ~/.xprofile to start in after I log in on LightDM, but what I would prefer is to start it immidiately after LightDM is started so that when I log in on VNC, I can see the LightDM prompt. How would I go about doing this?

3

You can do this by adding a systemd service to start the x11vnc server After= LightDM is started. Ensure that the service is run under user lightdm so that you don't get pesky XAuthority No protocol specified errors.

/etc/systemd/system/x11vnc@.service:

[Unit]
Description=Remote desktop service (VNC)
After=display-manager.service

[Service]
Type=simple
User=lightdm
ExecStart=/usr/bin/x11vnc -display %i                      
Restart=always
RestartSec=3

[Install]
WantedBy=graphical.target

After=display-manager.service tells systemd that the display manager (LightDM) needs to be running before this service can be started.

Type=simple says that the process is non-forking, the command under ExecStart stays running for the duration of the VNC server's life.

User=lightdm says that the process under ExecStart should be run by user lightdm, a system user whose purpose is to run X clients for the duration of the LightDM login prompt. This user owns the X server, so in order to have applications run in the login prompt, you need to run them as this user.

ExecStart=/usr/bin/x11vnc -display %i is the command to run when this service is activated, it says to start x11vnc on display %i, which is referring to whatever comes after the "@" symbol when you start the service.

Restart=always says that whenever the service fails to start, try again.

RestartSec=3 says to wait 3 seconds each time you retry.

WantedBy=graphical.target says to run the service whenever systemd brings up the graphical system (legacy runlevel 5).

To load the unit (make systemd "see" it), run the command

# systemctl daemon-reload

To enable it (make it start on boot), run the command

# systemctl enable x11vnc@<your-$DISPLAY-here>

where <your-$DISPLAY-here> is the X display that you want to give VNC access (usually :0)
To start it, run the command

# systemctl start x11vnc@<your-$DISPLAY-here>

Ditto about the <your-$DISPLAY-here>.

Note that you can run multiple independent services under the same unit file, by passing different displays after the "@". For example, you could run multiple VNC servers on X displays :0, :1, and :2, on ports 5900, 5901, and 5902 with x11vnc@:0, x11vnc@:1, and x11vnc@:2.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.