• July 15, 2024
view of a desktop screen

Notes: Autostart VNC server on Debian/RPi

To share a desktop on a remote computer using a VNC server. This is done on a Raspberry Pi desktop. The Pi computer auto-starts and logs-into a default user. SSH is already enabled, since the computer is fully remote. If local access, this can be done at the PC.

Start with a SSH connection into computer and install x11vnc:
~ $sudo apt install x11vnc
review and approve any additional packages that are needed

The command to join the already running desktop session, ie: desktop that is already auto-logged into:
~ $x11vnc -noxdamage -display :0 -safer -once

Note: adding to the init.d or other startup scrips fail. Probably because the x11 session hasn’t started yet, and nobody is logged in – there isn’t anything for the VNC server to connect to.

We are going to create a new login item and set it to autostart when the desktop starts. This is going to work if auto-login is enabled.

Go to the home folder on the remote computer. In the pi os with one user, that is the location that you start with when you login via SSH.

change to the hidden config folder
~ $cd .config

The autostart folder probably doesn’t exist… Look for it with:
~/.config $ls

If you see an autostart directory perfect! Otherwise, make one with:
~/.config $mkdir autostart

Go into the autostart folder:
~/.config $cd autostart

Let’s make a new startup program link. This will have the command to start the VNC server. We are using nano file editor and calling the new file shadowVNC.desktop. You can pick any other name, but keep the `.desktop’ extension:
~/.config/autostart $nano shadowVNC.desktop

This file will have the Desktop Entry title, a name for the program (this is what shows up in the GUI, not the file name), a Generic Name, some comments, and the actual script to run, does it need a temrinal, and should it autostart? Or just copy/paste the following into the editor.

[Desktop Entry]
Name=shadowVNC
GenericName=A VNC Server
Comment=Starts a VNC shadow server
Exec=/usr/bin/x11vnc -noxdamage -display :0 -safer -once
Terminal=false
Type=Application
X-GNOME-Autostart-enabled=true


Save the file with Control+O, hit enter, exit with Control+X

Now we set this file’s properties with:

~./config/autostart $chmod 755 shadowVNC.desktop

At this point, you should be able to restart the computer and the VNC server will auto-start after everything is booted up and the GUI logs-in.

However, if you want to double-check it first. Start the VNC server from the command prompt using this command:
~ $x11vnc -noxdamage -display :0 -safer -once

Now, use the VNC viewer to connect to the remote computer. The desktop should show up, and you should be able to navigate about it. Let’s check the autostart programs.

Click the menu icon > Preferences > Main Menu Editor

computer start menu, preferences sub menu selected, main menu editor selected

This program lets you configure what is shown in the start menu. Click on Preferences > enable the option for showing Desktop Session Settings. Then, click “OK”

Program window from Main Menu Editor. Two boxes, left box with a list of applications and preferences selected. Right box has two columns, check enabled box in front of the item called desktop session settings

Click the Start Menu > Preferences > Desktop Session Settings. You should see the new “shadowVNC” Application listed there, and it should have a check in the enabled column.

Desktop screen, start menu selected, preferences sub-menu selected, desktop session settings selected.  Click on this.
Computer window showing a list of applications, a center frame, two columns Enabled and Application.  In application shadow V N C is shown. In Enabled column, a checkmark is present.

At this point. Click “OK” then reboot the remote computer to ensure the VNC service starts okay. The SSH connection and VNC connection should terminate when you reboot.