SSH X forwarding
I've recently been playing with a beta Arduino type add on board for the Raspberry Pi, it is by Alex Eames, the same man that is behind RasPi.TV and more recently RasPiO. The board is called the RasPiO duino, it fits directly onto the Raspberry Pi GPIO pins and contains an ATMega 328 micro controller.
Alex has designed it to be programmed directly from the Pi, using the Arduino IDE. This will be a very simple way to get people into Arduino type programming and associated electronics. However what do you do if your Pi is running headless?
There are a couple few options
Plug it into a monitor, ok for some. But I do not have any spare monitors and my TV seems like it is hard wired to show only CBeebies!
Install a VNC server and connect to the Pi from a more convenient laptop. Quite a good solution but can be a bit laggy.
Use the X forwarding facility over an SSH connection from a more convenient laptop.
This final option is the one I like the best and I shall describe my experience with it here. With X forwarding it is possible to start an SSH connection, then start a graphical program from the command line and it should then open up in an X window on the local computer. So the end result is the graphical program running in a window on the local computer but the program is actually running on the remote compute, in my case a Raspberry Pi. The program will have access to all the resources on the remote computer just as if you were running it whilst sitting at the remote machine.
Now, I had read about this in the man pages of SSH and thought I understood how to use it, but just could not get it to work, so I gave up.
A few weeks later I was at the Ipswich Makerspace and got a demonstration of how it should work, just as I has tried previously, so what was the problem. Well the demo was on a Linux machine, I had been using a Mac. After seeing it work I started thinking about why it was not working and thought it could be because I did not have an X window system installed on the Mac. After a bit of Googling I found XQuartz, this was linked to from the Apple support pages. I downloaded and installed it and tried an X forwarding session over SSH again, viola, it worked.
So, how do we set up X forwarding then.
Well, first we need an X Window system
Mac - use XQuartz
Windows, try XMing, note I found this via a google search, there are other alternatives and I have not tried this one works, but it's probably a starting point
Linux - No further software required, Linux is based on X Window, there may be exceptions though
The SSH daemon on the remote machine also needs X forwarding enabled. On the remote machine open /etc/ssh/sshd_config in your favourite editor and ensure it contains the following
X11Forwarding yes
So the usual SSH command is
ssh user@ipaddress
where
user is the user name on the remote computer
ipaddress is the IP address of the remote machine. This will give you a standard SSH session
To start an X forwarding session this will simply be
ssh -X user@ipaddress
Make sure you use a capital X
So far it looks just like a standard SSH session. To open a graphical window from the remote machine just type in the command. For example the Raspberry Pi comes with the LeafPad text editor. try typing
leafpad
If all has gone well, you should now have the LeafPad app open on your local machine but running on the remote machine. Try using the file, open command, the remote computer file system will appear.
Another program worth trying, if you have it, is Arduino. This will open the Arduino IDE and enable you to program Arduino devices connected to your remote machine. In my case the RasPiO duino.
Now there is a problem with X forwarding. As far as I see there is no way of running programs as root. So if you want to install a new package and want to run synaptic, it will not work.
However even with this limitation it is extremely useful to know about this feature and I know I will be using this lots in the future.











