Sometimes you have a RPi attached to a screen, but no keyboard or mouse attached and want to run GUI applications on it via SSH. This will also let you cross-compile RPi applications on a development machine and test them on the real machine.
Prepare the RPi for ssh access
To enable SSH access on a freshly installed RPi, put a file called ssh into the boot directory of the SD cards before booting up the first time. To enable WiFi you need to add a wpa_supplicant.conf file.
Set up the RPi
To log into the remote RPi wait for it to come online and then run:
ssh <PI_ADDRESS> -l <PI_USER>
where PI_ADDRESS is the IP adress on your network and the PI_USER is usually “pi”.
Now make sure your run “raspi-config” and set up your locale, keyboard layout etc. properly.
To run a GUI application you will need an X-server. If you have a full-blown desktop installation it is already installed, put if you use e.g. the “Lite” version of Raspbian you need to install the necessary packages:
sudo apt install --no-install-recommends xserver-xorg x11-xserver-utils xinit
If you now run applications remotely you might get some errors:
/usr/lib/xorg/Xorg.wrap: Only console users are allowed to run the X server
and / or:
xf86OpenConsole: Cannot open ... console ... (Permission denied)
To fix that, edit /etc/X11/Xwrapper.config and change the line “allowed_users=console” to:
Now you should be able to run graphical applications using:
Xinit docs are here. You can also use startx instead. All xserver options are here.
If you want to run your application on startup, see this. If you want to set a webbrowser kiosk and run chromium, see this tutorial.