For most development purposes a simple SSH (Secure Shell) running in a terminal suffices when working on a Raspberry Pi. Yet, there are times when a GUI program on the Pi would be useful. In this instance you could drag out your monitor and keyboard to connect the Pi. This can be annoying if you only need a program for a short time and have your Pi in a closet (as I often do). If this is the case, you can use a remote desktop tool from another computer to open the program. By default most Raspberry Pi's have a mechanism called X11 forwarding turned on when you SSH to them. This process allows a user to start applications on the Pi, and forward the application display to the host machine.
- Raspberry Pi
- Terminal Emulator (Personal favorite right now is Hyper.is)
Open up your terminal emulator of choice. Then run the following SSH command with the ipaddress replaced with whatever your Pi is on.
ssh -X pi@<ip_address>
Log in with your normal
pi login and you should see a normal ssh bash prompt from your Pi.
Opening a program
To open a graphical program and forward the display to your connected host machine run the following command:
nohup chromium-browser &
This example would open the Chromium browser. You can, however, replace
chromium-browser with any graphical program you have installed on your Pi. The
nohup command runs the argument command immune to hangups and with a non-tty output. This helps the X11 forwarding to go smoother. The
& character at the end of the command holds open the terminal while you are using the program. This does mean that if you want to run more terminal commands while a program is running; you will have to ssh to the Pi on another terminal window.
In this short article we saw how to use X11 forwarding to open graphical programs from a Raspberry Pi on a connected machine. This can be useful for when you need to do a simple task and a GUI tool is easier or more familiar for you. This process does not run super well on a Pi and can cause the forwarded program to lag at times. I would not recommend using it for a program you are going to use a lot. If that is the case then I would suggest connecting a monitor and keyboard.