How to SSH into Raspberry Pi without password

How to SSH into Raspberry Pi without password

I have more than three Raspberry Pi in the house. It can get tiring to connect to each one with a password. One way to avoid having to type a password during SSH is to use SSH Key.

SSH(Secure Shell) Key is basically a really really long (about 600 chars long password). The most commonly used is the 2048 RSA encryptions.

Step 1: Check for existing keys
If you have ever created a SSH Key, you can use the same one or create a new one. To check if you already have SSH key on your machine, goto the folder:

cd ~/.ssh


ls ~/.ssh

If you see any file in there that ends with *.pub that is your public key. You should also see a private key without the .pub extension with same name. Below you can see id_rsa and are the keys on my machine.

config		id_rsa	known_hosts

If you want to use the same keys, then skip the next step to generate new ones.

Step 2: Create a new SSH Key

Type the following on your Terminal:


You will see the following output:

neo@Sushants-MBP .ssh % ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/neo/.ssh/id_rsa): my_key
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in my_key.
Your public key has been saved in
The key fingerprint is:
The key's randomart image is:
+---[RSA 3072]----+
|                 |
|           . .   |
|   ...       . + |
|   ....  . .=    |
|    o.o..S+o.o   |
|   .  =.o o=     |
|  .   .= ...+ o .|
|   .+o....o..o o.|
|   o**+o...+. O.E|
neo@Sushants-MBP .ssh %

Above, I entered my_key as the name of my key, followed by a secret passphrase. The passphrase is optional, you can skip it by pressing enter.

Passphrase is important because if I copied your keys, then I could impersonate you and gain access. The passphrase only you will know.

This will generate a new key for you in the .ssh folder.

neo@Sushants-MBP .ssh % ls
config		id_rsa	known_hosts	my_key

Step 3: Add your key to the Pi

Run the following command to copy your key

ssh-copy-id <USERNAME>@<IP-ADDRESS>

This will copy the key over to the Pi. Now try to ssh into your Pi and you should login without entering password!


Next I will talk about adding all your hosts in the SSH config that way you will not have to type USERNAME@IP-ADDRESS every single time. Instead it will be as simple as SSH Pi and it will connect to that Pi. Thanks for reading!