Remote Raspberry Pi Access - The Command Line
I must admit that I rarely hook my Raspberry Pi's up to a screen. Instead, I access them remotely from one of my other PCs; what I mean by this is that I use the keyboard, mouse and screen of my PC to control the Raspberry Pi, displaying what is on the Raspberry Pi using one of three different methods. I have already written about using VNC to display what is on the desktop of the Raspberry Pi.
However, much of the time I just want to use the terminal or command line interface. For that, I use SSH, or Secure SHell. You are only able to type commands into a window on your PC, which are transferred to the Raspberry Pi and run.
Example Terminal Window
Setting up the Raspberry Pi
The Raspberry Pi needs to be running an SSH server. This may already be running. To find out, run the following in a terminal window on your Raspberry Pi:
ps ax | grep sshd
If the SSH daemon is already running, then you will see a line similar to this:
2163 ? Ss 0:00 /usr/sbin/sshd
In which case, you don't need to do anything. If you don't see that line, then you need to switch the SSH daemon on using the Raspberry Pi configuration program:
sudo raspi-config
This will display a list of options:
Using the down cursor key, move down to Advanced Options and press the return key.
And under there, choose the following line:
And then choose the option to Enable SSH and press return:
Exit the configuration tool by using the right cursor key to highlight Finish. The secure shell server will then start, enabling you to remotely access your Raspberry Pi using a SSH client from another computer.
But won't that mean that everybody can access your Raspberry Pi? No, it does not - you still need a username and password to log in, and everything that goes between your computer and the Raspberry Pi will be encrypted - hence the name of Secure Shell!
SSH Clients
You will also need an SSH client on the computer that you are using to access the Raspberry Pi, whether PC, Mac, Android or another Raspberry Pi.
The Raspberry Pi already has an SSH client built in. Just type ssh pi@otherpi
(where 'otherpi' is the hostname or IP address of the Raspberry Pi you want to connect to) in a terminal window. You will be prompted for a password, and then you are in.
On your PC and Mac there are a number of different clients. One of the simplest is 'KiTTY', which offers more than just SSH. You can download it from here.
On installing and running, you are presented with the KiTTY configuration window.
All you need to do is enter the hostname or IP address of your Raspberry Pi and select SSH. This should automatically set the port number to 22. Click on 'Open' and the terminal window will open requesting the username of your Raspberry Pi - which is probably 'pi', followed by the password - the default is 'raspberry'.
You are now able to run commands on your Raspberry Pi as though you were running directly on your Raspberry Pi.