Configuring the Raspberry Pi as an SSH Server


Introduction

Setting up an SSH server on the Raspberry Pi allows remote login and command execution from another machine. The display of the originating machine is used. This is handy since I do not have exclusive use of the TV display at home. Subsequently, I connect remotely from a Linux or Windows client (through the use of Putty) that is connected to the Raspberry Pi via an Ethernet connection. Furthermore, I can configure the Rapsberry Pi to share the Internet connection of the client machine as detailed here.

This post is structured as follows. Section 1 details how to configure the SSH server on the Raspberry Pi. Section 2 details how to connect to the Raspberry Pi from a Linux client. Section 3 describes how to use RSA public/private keypairs to authenticate user ssh sessions, instead of passwords.

1. Configuring the Raspberry Pi for SSH

To start with we first need to temporarily connect the Raspberry Pi to a suitable display device and check that it has the SSH server installed. Following this we will change the default password for user pi and assign the Raspberry Pi a static IP address.

Type the following in a terminal session:

 sudo service ssh status

If an ssh server is started you should receive a response that service sshd is running. If it is not then type the following in a terminal session:

 sudo raspi-config

This will start a configuration utility provided with the Raspbian distribution. Select the menu option for ssh and then choose to enable the ssh server. Reboot the Raspberry Pi.

Assign the Raspberry Pi a static IP address for the Ethernet interface by following step 2 of this page.

Finally, change the default password assigned to user pi by typing the following in a terminal session on the Raspberry Pi:

passwd pi

You will be prompted for the current password which should be raspberry When prompted enter the new password that you wish to use.

Note that by default the SSH server on the Raspberry Pi is configured to permit root (administrator) logins and uses the default port number, 22. To increase security this can be altered by changing the config file /etc/ssh/sshd_config on the Raspberry Pi.

2. Testing it out from a Linux client

I tested this from an Ubuntu machine. Instructions for using a windows client are detailed here.

Open a terminal session on the Linux client and type the following:

ssh pi@192.168.0.2

You will need to substitute 192.168.0.2 with the static IP address assigned to the Raspberry Pi. This can be determined by typing

ifconfig eth0

in a terminal session on the Raspberry Pi and inspecting the IP address detailed in the inet addr heading.

If the ssh request is accepted you should be prompted for a password for user pi. You should then be logged in. Type exit to quit the SSH session.

3. Generating public/private keypairs to authenticate a user

This section details how to generate public/private keypairs to authenticate a user from a Linux client machine. Instructions for using a windows client are detailed here.

In a terminal session on the Linux client enter the following:

mkdir ~/.ssh
chmod 700 ~/.ssh
ssh-keygen -t rsa

This will generate and store the public/private key pair in directory .ssh on the client. Accept the default key file location when prompted and enter a passphrase for the keys.

Now copy the public key over to the Raspberry Pi by typing the following command in a terminal session:

ssh-copy-id <userid>@<hostname or ip address>

For example, my Raspberry Pi is assigned the static IP address of 192.2.168.0.2. I connect to it by typing the following in a terminal session:

ssh-copy-id pi@192.168.0.2

Enter the password for user pi. Following this the public key file will be copied to the following file .ssh/authorized_keys on the Raspberry Pi.

Now try to login by typing the following into a terminal session:

 ssh pi@192.168.0.2

You should be prompted for your passphrase. Enter your passphrase and you should be logged into the Raspberry Pi.

15 thoughts on “Configuring the Raspberry Pi as an SSH Server

  1. Pingback: Kamera pro Raspberry PI | RaspiShop.cz

  2. Pingback: Raspberry Pi: Sichern und Wiederherstellen von Daten auf dem Raspberry PI – Backup Restore mit Synology als Host | Robins Blog - Technik und Multimedia

  3. Pingback: Raspberry Pi: configurazione rapida | Nazionlinux

  4. Pingback: Raspberry Pi: configurazione rapida | Nazionlinux

  5. tinnitus miracle scam

    Magnificent beat ! I would like to apprentice while you amend your website, how could i subscribe for a blog site?
    The account aided me a acceptable deal. I had been a little bit
    acquainted of this your broadcast provided bright
    clear idea

    Reply
  6. icloud

    Heya i’m for the primary time here. I found this board and I in finding It really useful & it helped
    me out much. I am hoping to provide one thing back and help others like you aided me.

    Reply
  7. icloud bypass cheat

    Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest
    twitter updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you
    would have some experience with something like this.

    Please let me know if you run into anything.
    I truly enjoy reading your blog and I look forward
    to your new updates.

    Reply
  8. Pingback: BibSonomy :: url :: Configuring the Raspberry Pi as an SSH Server | Roughlea

  9. King

    What’s up to all, the contents existing at this web site are actually awesome for people knowledge, well,
    keep up the good work fellows.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s