Comprehensive Guide to Setting Up x11vnc on Ubuntu: Installation, Service Configuration, and Security
Remote desktop access can significantly enhance productivity, whether for server management or accessing your desktop from another location. x11vnc offers a straightforward solution for connecting to your existing X session on Ubuntu. This guide covers the x11vnc installation, securing it with a password, configuring it as a systemd service, and identifying the correct user ID (UID) for a smooth setup.
Installation of x11vnc
If x11vnc isn’t already installed on your system, you can install it via the package manager:
sudo apt update
sudo apt install x11vnc
Creating a Secure Password for VNC Access
To ensure your x11vnc sessions are secure, it’s crucial to set up a password:
x11vnc -storepasswd
This command generates a password file located at /home/yourusername/.vnc/passwd. Make sure to replace yourusername with your actual username.
Determining the Correct User ID (UID)
Knowing the correct UID, especially for systems that use a display manager (like GDM), is essential for setting up x11vnc as a systemd service. The UID helps reference the correct user’s Xauthority file for authentication. List sessions and their UIDs with loginctl:
loginctl
Identify the session related to your display manager (gdm often) and note the UID. In this example, 121 is the UID for gdm:
$ loginctl
SESSION UID USER SEAT TTY
18 1000 user pts/0
c1 121 gdm seat0 tty1
2 sessions listed.
Configuring x11vnc as a Systemd Service
Configuring x11vnc as a systemd service ensures it starts with your system and runs in the background.
Step 1: Create the Systemd Service File
Create x11vnc.service:
sudo nano /etc/systemd/system/x11vnc.service
Insert the following configuration, adjusting paths and the UID as needed:
[Unit]
Description=Start x11vnc at startup.
After=multi-user.target
[Service]
Type=simple
Environment="DISPLAY=:0"
Environment="XAUTHORITY=/var/run/user/121/gdm/Xauthority"
ExecStart=/usr/bin/x11vnc -auth /var/run/user/121/gdm/Xauthority -forever -loop -noxdamage -repeat -rfbauth /home/user/.vnc/passwd -rfbport 5900 -shared
[Install]
WantedBy=multi-user.target
Step 2: Enable and Start the Service
Enable the service, start it, and check its status:
sudo systemctl daemon-reload
sudo systemctl enable x11vnc.service
sudo systemctl start x11vnc.service
sudo systemctl status x11vnc.service
Conclusion
With x11vnc now installed and set as a systemd service, you’re equipped for efficient remote access to your Ubuntu desktop. Remember to replace placeholders like 121 and user with the actual UID and your username as determined earlier. This guide ensures x11vnc is configured for secure and reliable remote desktop access.