Are you tired of typing user name or password each time accessing your Raspberry Pi via ssh? Here is a solution with security benefits added up. In this setup we’ll use two kind of keys i.e. public & private to access our Raspberry Pi. Public key is stored (discussed under Server Side heading below) on Raspberry Pi and private key is used by PuTTY (Client Side) to authenticate the login.
PuTTY comes with another application named as PuTTY Key Generator. We’ll use it to generate our private & public keys. Launch the PuTTY Key Generator and hit the Generate button. Now it will ask you to move your mouse cursor on a grey-green rectangular area for generating randomness. Just move your cursor up and down, left and right over the rectangle until green bar fill the space up and soon it will end up creating our desired keys.
Server Side:
- Login to Raspberry Pi using ssh using PuTTY and issue the commands below
mkdir .ssh/ nano .ssh/authorized_keys
- The last command given above, will open a new file “authorized_keys” in nano editor
- Open PuTTY Key Generator and copy the public key starts with “ssh” and paste it in nano editor using right mouse button
- Save the file by pressing “Ctrl” and “X” key followed by “Y” and “Return” key
- Submit the commands given below
chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys chown $USER:$USER ~/.ssh -R sudo nano /etc/ssh/sshd_config
- Go down in “sshd_config” file and find line “AuthorizedKeysFile“
- Remove # in start of line with “AuthorizedKeysFile” word
- Save the configuration file by pressing “Ctrl” and “X” key followed by “Y” and “Return” key
- reboot your pi using sudo reboot command
Client Side:
- Open PuTTY Key Generator and hit “Save private key” to save the key file in an appropriate place in your pc
- Open PuTTY and navigate to SSH > Auth
- Click on browse under “Private key file for authentication” and select the the private key file store on your pc
- Save the profile as discussed under second paragraph of Accessing Raspberry Pi via SSH using PuTTY
- Click “Open” to launch the ssh session and you will not be asked for password again