SgtPooki
By:
SgtPooki

SSH authentication failures: Server refused our key

September 14, 2014 6.1k views

I have set up public key authentication before and never had this much trouble.. I am not sure what I am missing, but I have done all of the following:

  1. Ensured the private and public key match (they were created by puttygen, and i use the same key for github )
  2. PubkeyAuthentication is set to yes
  3. AuthorizedKeysFile %h/.ssh/authorized_keys
  4. AuthorizedKeysFile has my public key in it.
  5. AuthorizedKeysFile is set to mode 600 (i've tried 644, 700, 777.. i know ssh server usually blocks any attempt to use these if permissions are too open, but idk what else to try)
  6. ~/.ssh is set to mode 700
  7. id_rsa.pub is set to mode 600
  8. The user and group are set to the proper user.. what am I missing?
1 comment
  • If NOT logging in as root its also important to make sure that the ownership privileges are set properly in the home directory. Otherwise the user won't be able to SSH into the server.

2 Answers

Ok.. apparently it was an issue with copying the file over a remote connection.

I ran dos2unix on my idrsa.pub, then cleared out authorizedkeys and then cat idrsa.pub >> authorizedkeys...

boom, it works. Thanks to DEBUG3. (Why doesn't verbose give key failure information....?)

I also had this same issue.

I solved it by

  1. Running puttygen
  2. Loading the private key I had generated
  3. Copying "Public key for pasting into OpenSSH authorized_keys file" into a new pub_key.txt file locally
  4. Using winscp to copy that file up to my server under the .ssh folder
  5. Deleting the authorized_keys file via rm authorized_keys
  6. Installing dos2unix via sudo apt-get dos2unix (I'm running Ubuntu)
  7. Converting the windows generated file to unix style line endings via dos2unix pub_key.txt
  8. Copying the pub key into authorized_keys via cat pub_key.txt >> authorized_keys

This finally allowed me to putty into my box as all the tutorials described.

Have another answer? Share your knowledge.