Solving “Server refused our key” – The easy way

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:

  1. sudo mkdir /etc/ssh/publicSSHkeys # Create a folder for public SSH keys
  2. sudo mv ~/.ssh/authorized_keys /etc/ssh/publicSSHkeys/ # Move the authorized_keys file there
  3. 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.
  4. sudo service sshd reload # Then you just need to reload the server
  5. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.