How to Remotely access the Raspberry Pi using SSH

Developing applications for your Raspberry PI, you will often need to connect to the Raspberry PI from another computer to deploy code or run tests etc. The best way to do this is via SSH.

In this tutorial, I will provide instructions on how to enable SSH on your Raspberry Pi, which will enable you to remotely access the Raspberry Pi via SSH.

I will not provide a detailed discussion of the in depth discussion of SSH, but I will give you enough information to enable you to connect to your raspberry pi from another computer.

What is SSH

Secure Shell (SSH) is a command interface and protocol to enable the secure access to a remote computer. It is the tool of choice for Network Administrators, developers and programmers to access Linux Servers, Desktops and Devices remotely. 

SSH essentially enables you to connect to your Raspberry Pi from another computer and enable you to execute Linux based commands as if you are actually logged onto the computer itself.

This type of approach is handy if you want to code on the Pi from the comfort of your laptop. Using this approach you don’t need to connect your keyboard, mouse or TV to your raspberry pi, all you need to do is connect your raspberry pi to the network,  and you can connect to it.

Although this steps outlined here, are designed to work with raspberry pi, it is important to note that they can be used for any Debian based Linux distribution.

For this tutorial I have made the following assumptions;

  • You are confident with the basics of using the Raspberry Pi, and are able to boot your Pi to the command line
  • Your PI operating system is Raspbian
  • Your PI is already connected to your network
  • you want to connect via SSH to your Pi from another Linux based computer. 
ifconfig

The first thing we need to do once your PI has started up, is get the IP address of your PI. which we will use later on. So at the command line type in
ifconfig.

This command will show all the relevant network configuration for your PI. Your IP will displayed as inet addr. Make a note of this as it will be relevant later.

Information

You able to connect to your Pi via SSH from a windows based computer using an application called Putty ,  However I will not be covering how to use Putty

Enable SSH with Raspberry PI Configuration

If you are using the Raspbian Desktop you can easily configure ssh using the Raspberry Pi Configuration utility. Available at clicking the Raspberry Pi Logo in the top left hand corner:

Raspberry Pi Logo –> Preferences –> Raspberry Pi Configuration –> Interfaces

Then select enable on SSH

Install SSH on Raspberry PI using Terminal

Raspbian already has SSH prepackaged, however I am going to err on the side of caution and suggest we just install it anyway. If you are using a distro that does not have it it preinstalled

Shell

After the install is complete we’ll start the SSH Service

Shell

You are also able to stop and restart this service in a similar way i.e.

Shell

The one thing I like to do ensure the SSH service starts every time you boot the PI is use the following command which will update a config setting

Shell

You can now restart your PI and disconnect it from your Keyboard & Mouse and television if you choose but leave it connected to you network.

Open a terminal window on your linux desktop and connect to your PI using the IP address we retrieved earlier. Remembering the default username = pi and password = raspberry

Access Raspberry Pi using SSH

Shell

You can now start any commands you choose to the PI, and these commands will be executed directly on the PI.

To terminate your SSH session after you have finished simply type exit

raspberrypi-exit

How to access SSH from Windows

The above commands and processes were based on the assumption you were accessing the raspberry pi via ssh via another Linux or Mac OS system.

In order to untilise SSH on windows machines historically required making use of applications like PuTTY etc. However, since Windows 10’s April 2018 Update, a built-in SSH client is now enabled by default!

How to Use Windows 10 SSH Client

You can now use the SSH client by running the ssh command. This works in either a PowerShell window or a Command Prompt window, so use whichever you prefer.

To quickly open a PowerShell window, right-click the Start button or press Windows+X and choose “Windows PowerShell” from the menu.

To view the syntax of the ssh command:

Shell
SSH Windows Command Prompt
SSH Windows Powershell

To access your raspberry pi using ssh on Windows is similar to the above. All you need to do is either open a cmd window or a powershell window and using the ssh command with pi@ and the IP address you want to connect to.

Shell

Summary

The biggest benefit of being able to access your Raspberry Pi via SSH is that you don’t need to have the Pi connected to any screen, keyboards or mice. You Pi effectively becomes a little quiet, low energy consuming, low noise server/computer. As long as it has a network connection you can access it.

Gary Woodfine

Technical Director at Denizon
Gary is Technical Director at Denizon, an independent software vendor specialising in IoT, Field Service and associated managed services,enabling customers to be efficient, productive, secure and scalable in a way which helps them address and reduce their ecological impact.

Denizon's product line successfully integrate IoT, Artificial Intelligence and Blockchain technology to enable efficient, productive, secure and scalable solutions to help organisations address increasing energy demands, ecological impact and Health & Safety concerns of their staff.

Latest posts by Gary Woodfine (see all)