17

Using ssh keys to log into your RPi is much more convenient than typing the password everytime.

It's especially handy if you want to log in from automated scripts or use programs such as scp or rsync

So how do I set up ssh keys to log into my RPi?

John La Rooy
  • 11,947
  • 9
  • 47
  • 75

1 Answers1

16

Linux

If you've never heard of ssh-keys before, you'll need to generate one like this

$ ssh-keygen -t dsa

This creates a directory ~/.ssh/ and stores the key files

$ ls -l .ssh/
-rw------- 1 gnibbler gnibbler 668 Aug 22  2004 .ssh/id_dsa
-rw------- 1 gnibbler gnibbler 603 Aug 22  2004 .ssh/id_dsa.pub

You need to copy id_dsa.pub to the RPi. There is a very easy way to do this using a helper script.

$ ssh-copy-id -i ~/.ssh/id_dsa.pub pi@raspberrypi.local

You'll need to type the pi user password one last time

Next time you log in, you won't be prompted for a password

$ ssh pi@raspberrypi.local
Linux raspberrypi 3.1.9+ #174 PREEMPT Sun Jul 22 19:04:28 BST 2012 armv6l

The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law.

Type 'startx' to launch a graphical session

How do I disable password logins?

Once you have set up key-based logins, you don't need to log in using a password anymore; you can disable it, which is much more secure.

  1. First, log in to your Raspberry Pi and open /etc/ssh/sshd_config as root; for example, run sudo vim /etc/ssh/sshd_config.

  2. Find the line containing PasswordAuthentication; it probably reads #PasswordAuthentication yes.

  3. Change this line so it reads

    PasswordAuthentication no

  4. Restart your Raspberry Pi, or just sshd.

Arch Linux

To restart sshd on Arch, run sudo rc.d restart sshd.

Debian/Raspbian

To restart sshd on Debian based distributions, run sudo /etc/init.d/sshd restart.

John La Rooy
  • 11,947
  • 9
  • 47
  • 75