SSH Keys Authentication keeps asking for password

Solution 1:

I don't think your keys have been properly copied, if you have ssh-copy-id available I would recommend you use that.

$ ssh-copy-id user@remote_server
Password:

Once you have entered the password, your SSH key will be copied over and you should be able to just ssh without providing the password again.

Also check your SSH configuration on ServerB and check a couple of things.

$ vi /etc/ssh/sshd_config

Another thing is to check these settings:

RSAAuthentication yes
PubKeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys

The value of AuthorizedKeysFile is where you need to paste your public ssh key.

You can collect your SSH-Key information by using: ssh-add -L

Updated

When ssh-copy-id doesn't exist you can do the old way:

$ cat ~/.ssh/id_rsa.pub | ssh user@remote_host 'cat >> /home/user/.ssh/authorized_keys'

Solution 2:

Your debug log shows that the server did not accept any of your private RSA keys. You should either specify the specific correct keyfile or check that the server has the right public key file.

As @Fredrik said, permissions on files can also play a role. SSH will refuse to use public key entries that others can write to and private key entries that others can read.

Solution 3:

These problems (which are usually permissions related) are much more easily debugged from the server side. I recommend that you start another sshd in debug mode with: /usr/sbin/sshd -d -p 2222 which will start another sshd on port 2222, then run ssh -p 2222 user@sshserver on the client side. Watch what comes out of the sshd when your client tries to authenticate.

Permissions problems don't have to be just /home/$USER/.ssh. it could also be a problem with /, /home, or /home/$USER. If any of those are group writable it can be a problem.

Another common problem is that you mis-paste and put linebreaks in the middle of your key in the authorized_keys file

Solution 4:

You should check the permission of the files on the remote machine using ls -l ~/.sshand setup the permission:
chmod 600 ~/.ssh/authorized_keys
chmod 600 ~/.ssh/<private_key> Ex: chmod 600 ~/.ssh/id_rsa
chmod 700 ~/.ssh/<public_key> Ex: chmod 700 ~/.ssh/id_rsa.pub
chmod 700 /home/vmirea/.ssh

Solution 5:

Based on the above I cannot say what the problem is. However, most of times I've encountered this the reason has been that the keys have had their rights set to be too readable (as in readable to group or other, not just the user). That's where I would start looking.