Monday, 10 December 2012

SSH Key - Permission Denied

Everytime, i try to create a new RSA key-pair and configure the pairs on a linux box, i always get the Permission Denied (Public Key) issue and end up spending 10 minutes to find a solution.
So, after this post, i need not run around for the solution.

Make sure the permissions of the .ssh folder are 0700
Make sure the permissions of the authorized_keys file are 0600
Make sure the user owns the .ssh folder and contents 

Execute the following command:
sudo chown -R <<username>>:<<usergroup>> /home/<<username>>/.ssh
sudo chmod 0700 /home/<<username>>/.ssh
sudo chmod 0600 /home/<<username>>/.ssh/authorized_keys.
A little background on SSH key-pair,
Lets say that machine 1 (M1) wants to communicate with machine 2 (M2) using the SSH key-pair (private/public).
1. M1 uses its private key to communicate with M2. This private key is not known to anyone else. (usually this private key is available in /home/<<username>>/.ssh/id_rsa file)
2. M2 should have the M1's public key added to home/<<username>>/.ssh/authorized_keys.
From M1, ssh <<username>>@M2 would use the id_rsa private key by default.
Alternatively, the private key can be specified using the -i option as follows:
ssh -i mykey <<username>>@M2

1 comment: