A Raspberry Pi computer in housing
MAB32/Shutterstock.com

After setting up your Raspberry Pi, you may not need a display for it. When it comes time for maintenance tasks, like upgrades and reboots, you can use Secure Shell (SSH) instead of plugging in a monitor. We’ll show you how.

What Is SSH?

SSH, often typed all in lower case, stands for Secure Shell. It allows you to remotely connect to a server or system from another device using encrypted communications.

The primary benefit of SSH is the encryption itself. With less secure remote login protocols, such as FTP, everything is sent in plain text. A hacker can sniff out those communications and log things like usernames and passwords. Since SSH is encrypted, that’s no longer possible.

RELATED: What Is Encryption, and How Does It Work?

Before You Turn On SSH, Mind Your Security

Turning on SSH is easy, but let’s not get ahead of ourselves. First, you’ll want to make sure your Raspberry Pi is secure. That starts with the password for your user account.

Advertisement

When you first set up your Raspberry Pi, you should have been prompted to change your user account password. If you did not, you need to do so now. Open the terminal, then enter the passwd command.

passwd

You’ll be prompted to enter your current password, then choose a new one.

RELATED: 10 Ways to Generate a Random Password from the Linux Command Line

Discover the IP Address or Hostname for Your Raspberry Pi

You’ll also need to know the hostname or IP address of your Pi. From the terminal, type:

hostname -i

This will provide the IP addresses for your Raspberry Pi. There could very well be several listed if you are connected both through Wi-Fi and Ethernet. Most of the time, the address you want will begin with 192.168. Make note of the address or hostname for later.

With that out of the way, we can turn on SSH.

RELATED: How to Setup Wi-Fi On Your Raspberry Pi via the Command Line

Option 1: Enable SSH Through the Desktop

One way to turn on SSH is through the Raspberry Pi graphical configuration app. Just click the Raspberry icon in the top left corner of the screen, then click “Preferences.” Click “Raspberry Pi Configuration.”

Enable SSH on the Raspberry Pi desktop

In this app, click the “Interfaces” tab and look for “SSH.” Click the “Enable” radio button, then click “OK” to close the app.

Option 2: Enable SSH From the Terminal

Another method to enable SSH is from the terminal itself, command-line style. Type this command to enter the text-based configuration tool for your Raspberry Pi:

sudo raspi-config
Advertisement

Use the arrow keys on your keyboard to select “Interfacing Options,” then press the Enter key.

Select "Interface Options" in SSH configuration

Select “P2 SSH” and press Enter.

Select P2 SSH in the SSH configuration

When asked, “Would you like the SSH server enabled,” choose “Yes.” Press Enter again at the confirmation box, “The SSH server is enabled. Navigate down and select “Finish.”

Disable SSH Root Login

Once you’ve enabled SSH, there is another optional but highly recommended task. Leaving your root user able to SSH into your Raspberry Pi is a security risk, so we recommend disabling root login through SSH. Remember, you can always issue administrative commands from your regular user with sudo.

In your Terminal window, enter this command:

nano /etc/ssh/sshd_config

Now, find this line:

#PermitRootLogin prohibit-password
Note: The line in the configuration file could also read #PermitRootLogin yes.

Edit the line to read as follows:

PermitRootLogin no

Save and close the file by pressing Ctrl+X, then Y . Now, you should reboot the SSH server with this command:

/etc/init.d/sshd restart

There are other steps you can take to secure your SSH server even further, so be sure to consider how at-risk your Raspberry Pi can stand to be.

Log Into Your Raspberry Pi From Another Computer

Once those steps are complete, you’re ready to log into your Raspberry Pi from any computer on your local network. With the IP address or hostname you noted earlier, you can ssh into your Pi. That’s done using this command from your other computer:

ssh pi@[address]
Advertisement

If your Raspberry Pi’s address is 192.168.0.200 , for example, it will look like this:

ssh pi@192.168.0.200

The first time you ssh into your Pi, you’ll be asked to accept the encryption key. Just press Y , and you’ll connect and be prompted to enter your password. That done, you’ll be logged into the Raspberry Pi and can do whatever tasks you need.

In addition to issuing commands, you can also use SSH for other purposes, such as to tunnel your traffic, transfer files, mount remote file systems, and more. If you’re concerned about security with your Pi, consider setting up two-factor authentication.

RELATED: How to Set Up Two-Factor Authentication on a Raspberry Pi

Profile Photo for Jeff Butts Jeff Butts
Jeff Butts was a nerd long before they got their revenge. He’s been voiding warranties since the early 1980s, when he took apart his uncle’s 286 to try coaxing a bit more power out of the Hercules graphics controller. He holds a Master of Arts in Professional Writing & Editing as well as a Master's in Computing and Information Systems. In addition to his work at How-To Geek, Jeff also writes for The Mac Observer.
Read Full Bio »

The above article may contain affiliate links, which help support How-To Geek.