Raspberry Pi With Remote Screen Sharing – A Quick Installation Guide

It’s been a while since I installed a headless Raspberry Pi from scratch with a desktop GUI to be accessed over the network. In the ‘early days’ of the Pi this used to be very simple: Get an image file from the Raspbian website, use ‘dd’ on Linux to copy the image to an SD card and start it. SSH was active by default and the username and password was known. Done! But then the project became very popular and these days things are a bit more complicated. I guess it probably turned out that having an open SSH port by default with default credentials is not ideal. Also, the makers of the Raspberry Pi have made some decisions that are not quite to my liking. So here’s a quick guide how to get a headless Raspi up and running with a GUI over the network WITHOUT using special installers and proprietary remote desktop viewers.

Open SSH Port

The first hurdle to overcome after copying the downloaded OS image to an SD card with ‘dd’ is to get an open SSH port on the Pi, as I didn’t want to connect a screen and keyboard. By default, the SSH port is closed these days and needs to be opened by putting a file called ‘ssh’ into the boot partition of the Pi. I was aware of this, so no surprise here.

The ‘pi’ User Doesn’t Work Anymore

The thing I wasn’t aware of or just forgot about: There is no default ‘pi’ user anymore, so I wasn’t able to logon over SSH. It turns out that a default user can be created with the Raspian installer tool, which I did not use. Why would I, ‘dd’ is straight forward and I don’t want to install any unnecessary tools!? The way to fix this is to put yet another file into the boot partition on the SD card called ‘userconf.txt’. To get the default pi user back with the default password, the following line needs to be put into the file:

pi:$6$c70VpvPsVNCG0YR5$l5vWWLsLko9Kj65gcQ8qvMkuOoRkEagI90qi3F/Y7rm8eNYZHW8CY6BOIKwMH7a3YYzZYL90zf304cAHLFaZE0

Yes, I do change the password on first login and disable password login in /etc/ssh/sshd_conf anyway, as I use ssh certificates instead of passwords.

RealVNC Thanks, But No Thanks – X11VNC For Me

Once SSH access over the network works, the next step is to get a graphical desktop up and running and access it over the network. Raspian’s solution is based on RealVNC, which I personally don’t like for two reasons:

First, the current settings block use of standard VNC viewers such as Remmina. This is probably because VNCs ‘traditional security’ is anything but secure anymore these days. I grant them that. I found a number of descriptions on the web on how to ‘downgrade’ the security to standard VNC passwords and unencrypted transmission, but none of them worked for me.

The second reason why I don’t want to use RealVNC is that the RealVNC viewer seems to be a proprietary product these days that is not part of the Debian sources. Also, the user is very much pushed into creating an account with RealVNC. It’s not required, but the option to skip this is somewhat hidden. Taken together, it’s a no-go for me.

So after some trial and error, I decided to disable the RealVNC Server on the Pi. Instead, I installed X11VNC and ran it from the command line:

sudo systemctl stop vncserver-x11-serviced.service
sudo systemctl disable vncserver-x11-serviced.service

sudo apt install x11vnc
x11vnc -usepw -display :0

On first invocation, x11vnc asks for a password (maximum length 8 characters) and then opens up port 5900 for an unencrypted connection. Yes, not secure at all, so I can understand why Raspian went the other way.

And just a note on security, because I don’t want to promote insecure configurations: I typically limit x11vnc to a local TCP port and use an SSH tunnel to go through for authentication and encryption, but that’s another story and obviously too complex for the majority of people experimenting with a Pi.

Disable Hardware Rendering

By default, the current Raspian image uses “GL Rendering in Hardware”. That sounds nice but unfortunately, the Chromium browser is unusable that way, it just keeps flickering, at least with x11vnc and no real monitor connected. The solution: Disable hardware rendering on the command line with ‘sudo raspi-config‘ in the ‘Advanced‘ menu in ‘A2 GL Driver‘, and reboot!

Virtual Screen Resolution

And finally, one more thing to do is to increase the screen resolution of the virtual display. This can be done on the GUI in:

'Preferences' --> 'Display' --> 'Resolution'

Note: There’s also a ‘Headless Resolution’ input field, but that doesn’t work with x11vnc. So ignore it!

Summary

Here we go, while it doesn’t take much to do to get a Raspi with remote GUI up and running, it still took me 2 hours because I had to get the details together from various posts, which took me around 2 hours. Next time, I’ll stick to my own description and I hope it might be helpful to others as well.

2 thoughts on “Raspberry Pi With Remote Screen Sharing – A Quick Installation Guide”

  1. FWIW, my Pi doesn’t run any GUI desktop (virtual or otherwise). It boots to a text console. I use SSH to log-in to CLI sessions. When I need to run graphical apps on it, I run an X11 server on my Mac (XQuartz) or Windows PC (via Cygwin) or Linux (its native desktop), set the DISPLAY variable on the pi and let the apps just open windows on the remote X server.

    Performance is fine over a LAN. I will agree, however, that X11 requires far too much bandwidth to be usable over the Internet (via VPN). But I never access my pi when away from home.

  2. For secure VNC, i do SSH tunneling a lot (I am just too stupid or lazy to configure and run Wireguard).
    Recently i found AVNC on F-Droid (https://github.com/gujjwal00/avnc). It supports defining a SSH Tunnel it will run VNC on. That spares me from start and running Termux with manual SSH tunneling when i want to use VNC from my Android. (That worked also quite well but is more tedious to configure and takes extra steps every time).

    There is a x11vnc client for Desktop Linux that has ssh tuneling included, too, but i run some elaborate scripting to setup SSH tunnels on my desktop and use the TigerVNC client (vncviewer in .deb based systems)

Comments are closed.