Gossh.. It delayed my works for almost two weeks until I figure it out today. The SSH key making works fine in ubuntu, but on CentOS, it somehow doesn’t works.
If “Server refused our key” error while login with private key happens even after you copied the public key into ~/.ssh/authorized_keys, then maybe it’s SELinux context issue.
when I tried to login using the private key, I got this:
Using username “root”.
Server refused our key
Then login into that normally (using your root password), and try this before you attempt another login using private key :
/sbin/restorecon -r /root/.ssh
And just make it sure you’ve set ~/.ssh into 700 mode, and ~/.ssh/authorized_keys into 600 mode
chmod 700 /root/.ssh
chmod 600 /root/.ssh/authorized_keys
They said :
Make sure that you setup correctly the selinux context of the public key if you transfer it to a CentOS 6 server with selinux enabled. Otherwise selinux might forbid access to the ~/.ssh/authorized_keys file and by matter of consequence key authentication will not work.
Hope it works with you.