Server refused our key

I have been trying all day to set up SSH keys on a linux server and Windows 7 client, finally with succes.

The way I managed to finally do it is like this:

  1. Log into your linux server
  2. Type:
    ssh-keygen -t dsa
  3. Accept default filename
  4. Provide a strong passphrase
  5. The keygen will create two files: id_dsa.pub, and id_dsa. The first one is the public key (.pub), the second one it the private key, copy this to your Windows 7 client.
  6. While stil on your server, now put the contents of id_dsa.pub into ~/.ssh/authorized_keys
  7. Make sure you
    chmod 600 ~/.ssh/authorized_keys
  8. Now move to your Windows 7 client and run puttygen.exe
  9. Load the id_dsa you have copied from the server
  10. Enter the passphrase
  11. Now use the save private key button to save the private key in putty .pkk format
  12. Now open putty and go to: Connection » SSH » Auth and browse for the .pkk to use as private key
  13. Now click open and you should be able to login into your server without the text: Server refused our key

If you followed the above and it still shows the text: Server refused our key, just read on…

Bonus steps that might solve your problem:

  1. In your server console issue the command: hostname
  2. Your hostname will be shown now, write it down or remember it
  3. Now start putty and in the Host Name (or IP address) input field enter that hostname (I am assuming you have allready set up a working hostname)
  4. With the .ppk selected as in step 11 press Open and you will be able to login without the text: Server refused our key

The first 13 steps are quite obvious, but it took me some time to notice that you really have to use the hostname. Before when I was just using a local IP address like 192.168.178.100 I could still login with putty, but the key would not be accepted, now that I’m using my hostname I can succesfully login on the server. There are a lot of tutorials like this one on the web, but none of them told me to use the hostname you have set up on your server!