These are the possible tricks as the solution to fix common error of passwordless SSH login configuration on most Linux distros. Hopefully one of these can help you easily gain access to your VPS / Linux-based server through your favorite SSH client.
Common error: Server refused our key
Solution #1: Usually this error is caused by incorrect file permission configuration. Try to chmod the folder and authorized_keys file into following:
chmod 700 ~/.ssh/ chmod 600 ~/.ssh/authorized_keys
Solution #2: Try to move the authorized_keys file location outside the home folder so the SSH daemon can access it even when you’re not logged in. Follow these steps:
- sudo mkdir /etc/ssh/publicSSHkeys # Create a folder for public SSH keys
- sudo mv ~/.ssh/authorized_keys /etc/ssh/publicSSHkeys/ # Move the authorized_keys file there
- sudo nano /etc/ssh/sshd_config # Modify sshd_config to the new location
change this… “AuthorizedKeysFile %h/.ssh/authorized_keys”
to this… “AuthorizedKeysFile /etc/ssh/publicSSHkeys/authorized_keys”
NOTE: Sometimes the “AuthorizedKeysFile” variable is commented out, so remove the number sign if it is.
- sudo service sshd reload # Then you just need to reload the server
- You’ll still need to make sure your public key is in /etc/ssh/publicSSHkeys/authorized_keys, and your SSH client (in my case Putty) is loading your private key. There are numerous SSH key tutorials on the webernets.
Solution #3: If you are on CentOS, try to restore file(s) default SELinux security contexts. Issue following command:
restorecon -R -v /root/.ssh
That’s all. Most welcome for any additional tips.