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?


1 Answer 1



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 [email protected]

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 [email protected]
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.


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

  • Please be aware that password-less ssh should only be used where you know the connection is already secure. Otherwise you are putting yourself at risk to save 10 seconds.
    – Jivings
    Aug 22, 2012 at 22:26
  • @Jivings Explain? Keys are always more secure than passwords. Aug 23, 2012 at 6:12
  • @gnibbler Would you accept an edit on how to disable password logins? Aug 23, 2012 at 6:13
  • @AlexChamberlain, of course Aug 23, 2012 at 6:20
  • @AlexChamberlain This answer says how to set up password-less keys. That's to what I was referring
    – Jivings
    Aug 23, 2012 at 6:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.