Setting Up Your Raspberry Pi For Headless Use With SSH
The Raspberry Pi is – as we’ve seen in several previous articles – an extremely flexible piece of hardware. Once you’ve installed an operating system, got to grips with the small dimensions, and found a case for it, you’ll be able to install media centre software and perhaps even begin programming software (after all, that’s what it was designed for!).
However, you might find that the business of plugging the Raspberry Pi into your big screen plasma TV – the only device in your house with a HDMI connection – is a bit tiresome while your family is watching their favourite show. Alternatively, you might have more than enough HDMI displays but not enough keyboards.
Benefits of SSH
Fortunately, the Raspberry Pi can accept SSH commands when connected to a local network (either by Ethernet or Wi-Fi), enabling you to easily set it up.
The benefits of SSH go beyond upsetting the daily screening of The Simpsons or the latest celebrity news – using your Raspberry Pi without a dedicated display (also known as “headless”) can allow you to leave the device set up in a particular configuration without the worry about anyone disrupting things.
Using the Pi as a NAS interface? No problem! If your Raspberry Pi spends its life as low-fi web server or Internet radio, then it has no need for a dedicated display.
This is where SSH comes in!
Setting Up the Raspberry Pi for SSH
In order to prepare your Raspberry Pi for remote connections over SSH, you should have first installed the Debian distro Raspbian, as described previously. By default SSH is enabled, but if you have it disabled you should enter the config screen to re-enable.
With your mini-computer plugged into the mains and with a keyboard and Ethernet cable connected, boot up and login to the device.
Once you’ve done that, enter sudo raspi-config to open the configuration screen, and use the arrow keys and Enter to select the Enable or Disable SSH option. In the next screen, select Enable, tap Enter and the in the final screen Enter again to select OK.
With SSH now enabled, you will be able to remote connect to your Raspberry Pi using an SSH client.
(Note that if SSH is not listed as a menu option, you are probably using an old build of the Raspbian distro and should update as soon as possible!)
Connecting to Your Raspberry Pi
Before connecting to your Raspberry Pi, you will need to check the IP address. There are a couple of ways of doing this.
The first, from the command line, is to enter ifconfig to display your network connection details, including the IP address. Alternatively, you can check your router for connected devices and ascertain the IP address that way.
With this information to hand, you’re now ready to connect with SSH.
If you’re using Windows, the best SSH tool is probably PuTTY, available from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html. Once downloaded (select putty.exe for this task), double click the executable – it will run without installation.
In the Session screen, add the IP address in the Host Name field and click Open. PuTTY will issue a security notice – click Yes to continue, and then login to the Raspberry Pi.
Moments later you will see the Raspberry Pi text-based interface!
You can now disconnect the keyboard, mouse and HDMI cable from your Raspberry Pi, and issue commands remotely.
Issuing Remote Commands to the Pi
Various commands can be issued remotely to the Raspberry Pi via SSH – pretty much anything that doesn’t disable or interrupt SSH or your network connection!
This will display a list of running processes.
$ ssh –V
Displays the current SSH version
Files can be copied to and from the Raspberry Pi using SSH:
localhost$scp loginname:/home/username/remotehostfile.txt remotehostfile.txt
localhost$scp localhostfile.txt loginname:/home/username/localhostfile.txt
Once you’re done, remember to safely shutdown your Pi with the command:
sudo shutdown -h now
(Changing –h to –r will reboot the device). This must be done before removing the power cable – failure to do so can easily lead to a corrupted SD card, which will mean reinstallation of the Raspian OS.
Updates, Application Installs and Command Line Use – by Remote!
There are certain things that SSH is no good for. For instance, it won’t allow you to access the Raspberry Pi’s GUI, but it will provide you with the means to run updates, install applications and use various built-in programs and tools from a different computer.
With the easy configuration of SSH by remote and commands listed above (and many more) you can quickly and efficiently send instructions to the device using PuTTY on Windows or via the native command lines tools in Mac OS X and other Linux distros.
All in all, if you own a Raspberry Pi you should be aware of how convenient and useful SSH is. If you plan to use SSH regularly, you might want to learn this boot partition hack to enable SSH quickly when you need it.
Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.