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. Create public/private key pairs to authenticate

This section details how to generate public/private key pairs 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.

Comments

15 responses to “Configuring the Raspberry Pi as an SSH Server”

  1. […] Um automatisiert (hier via Cron-Job) auf den Raspberry Pi zuzugreifen müsst ihr eine ID-RSA auf dem Pi kopieren, sonst kommt während der Scriptausführung eine […]

  2. bam Avatar
    bam

    mantap Bro! Thanks for sharing.

  3. […] Dalle impostazioni avanzate abilitiamo il server ssh; ci sarà da copiare la nostra chiave sul Raspberry (punto 3 di questa guida). […]

  4. […] Dalle impostazioni avanzate abilitiamo il server ssh; ci sarà da copiare la nostra chiave sul Raspberry (punto 3 di questa guida). […]

  5. tinnitus miracle scam Avatar

    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

  6. telnet router linux distro comparison Avatar

    Generally I don’t learn article on blogs, however I would like to say that this write-up very pressured me to take a look at and
    do so! Your writing style has been amazed me. Thank
    you, quite nice article.

  7. icloud Avatar

    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.

  8. icloud bypass cheat Avatar

    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.

  9. batman arkham city lockdown cheat Avatar

    Asking questions are really good thing if you are not understanding anything fully, but this
    article offers fastidious understanding yet.

  10. www.gmail.com Avatar

    It’s remarkable in favor of me to have a website,
    which is beneficial designed for my experience. thanks admin

  11. King Avatar

    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.

Leave a comment