[SSH]: Remote SSH to a Raspberry Pi without password (macOS, Linux)
bash
mac
09/25/2020
Overview
This post will show you how to establish SSH remote connection to a Raspberry Pi or other devices without using password via ssh-keygen
1. Connect to Raspberry Pi on terminal
Refer to this page if you need to find out local ip address of pi
2. Generate authentication key on pi
-t rsadefines encryption type
-b 4096uses 4096 bits
-Cprovides a comment (in this example, email)
This will prompt you to enter directory and passphrase of the key. Feel free to press enter to skip these prompts. The default directory is ~/.ssh where the two keys will be saved: id_rsa and id_rsa.pub
id_rsa.pub vs id_rsa
id_rsa is a private key, used to sign into a remote host
id_rsa.pub is a public key that needs to be supplied to the remote host via authorized_key file
3. Add generated key to authorized key
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keyThis will generate authorized_key that contains the public key
4. Set permissions for authorized key
chmod go= ~/.ssh/authorized_keychmod u=r ~/.ssh/authorized_key
go=adds other users for permission.gindicates other uses in the file's group, andoindicates other users not in the file's group.
u=rgives the owner of the file,u, permission to read
5. Move generated key to your device
Logout from pi machine to go back to your device that you wish to use to connect to pi. You'll need the private key, ~/.ssh/id_rsa, on your device in order to sign into the remote host, pi.
cd ~/Documents# Copies the private key from pi to the current directory of your device6. Connect without typing in password
Finally, use the below command to connect to pi without password
ssh -i ~/Documents/id_rsa [email protected]