Setting Up Your Raspberry Pi For Headless Use With SSH

muo rasppi intro     Setting Up Your Raspberry Pi For Headless Use With SSHThe 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.

muo raspissh ssh     Setting Up Your Raspberry Pi For Headless Use With SSH

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.

muo raspissh ifconfig     Setting Up Your Raspberry Pi For Headless Use With SSH

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.

muo raspissh tty     Setting Up Your Raspberry Pi For Headless Use With SSH

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!

ps ax

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.

The comments were closed because the article is more than 180 days old.

If you have any questions related to what's mentioned in the article or need help with any computer issue, ask it on MakeUseOf Answers—We and our community will be more than happy to help.

9 Comments -

0 votes

thedude

what about “ssh -X” wont that allow X11 forwarding so you can access raspberry pi’s gui’s ?
Just guessing,..I dont own a pi, but I do have a few linux and Sun boxes.

0 votes

Sean A

cool idea i would love to try it

0 votes

Aneesh Anand

saw one recently. Wondering how it can replace my desktop PC for gaming. Any idea i can do it like that?

0 votes

Christian Cawley

The best way is to stick to retro, pre 2000 titles, I would say, using emulators. I may be wrong with the day, it could be +/- a couple of years.

RPi excellent for many things but it won’t replace a gaming PC.

0 votes

Aneesh Anand

thnx for the reply. But this as a media player, (put in a box, connect the IDE HDDs which i managed to put together and extend to a converter cable with USB out) will do any good? I am using the current HDD box setup directly with a USB enabled LED TV now. Will I get a faster interface where i can browse, search, copy and delete (as in windows/ubuntu), and more media format and resolution support?

0 votes

Ahmed Khalil

we need more technical articles about this computer and how to make use of it

0 votes

Luis Garcia

hiya, i have an issue with my rasp and ssh. here’s the thing ssh works (inside and outside of my network) i can log in perfectly but after a while it just stops i cant ssh into the raspberry at all, pings also sometimes return but most of the time its just a timeout.

my desktop monitor has a few usb ports i have it connected there i find it supplies enough power to run everything. My question is does it really? does lack of power affect ssh functionality? should i just use a direct DC connection?

0 votes

Christian Cawley

Great question – in my experience I would say always use the DC mains adaptor to power the Pi.

0 votes

Luis Garcia

hey there, been connected directly to DC for a day now with 0 ssh issues. Aparently once the monitor goes to stand by there isnt enough power for the raspberry.