Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a 12.10 server setup in a virtual machine with its network set to bridged (essentially will be seen as a computer connected to my switch).

I installed opensshd via apt-get and was able to connect to the server using putty with my username and password.

I then set about trying to get it to use public/private key authentication. I did the following:

  1. Generated the keys using PuttyGen.
  2. Moved the public key to /etc/ssh/myusername/authorized_keys (I am using encrypted home directories).
  3. Set up sshd_config like so:

    PubkeyAuthentication yes
    AuthorizedKeysFile /etc/ssh/%u/authorized_keys
    StrictModes no
    PasswordAuthentication no
    UsePAM yes

When I connect using putty or WinSCP, I get an error saying No supported authentication methods available (server sent public key).

If I run sshd in debug mode, I see:

PAM: initializing for "username"
PAM: setting PAM_RHOST to ""
PAM: setting PAM_TTY to "ssh"
userauth-request for user username service ssh-connection method publickey [preauth]
attempt 1 failures 0 [preauth]
test whether pkalg/pkblob are acceptable [preauth[
Checking blacklist file /usr/share/ssh/blacklist.RSA-1023
Checking blacklist file /etc/ssh/blacklist.RSA-1023
temporarily_use_uid: 1000/1000 (e=0/0)
trying public key file /etc/ssh/username/authorized_keys
fd4 clearing O_NONBLOCK
restore_uid: 0/0
Failed publickey for username from port 14343 ssh2
Received disconnect from 14: No supported authentication methods available [preauth]
do_cleanup [preauth]
monitor_read_log: child log fd closed
PAM: cleanup

Why is this happening and how can I fix this?

share|improve this question
In my case, I have two AWS instances. One of them is working flawlessly, the other one is working when connecting through Intellij Idea, but not from Putty, but it was working at the beginning. So in my case it must be something about putty – Marian Klühspies Nov 23 '15 at 12:00
up vote 22 down vote accepted

Problem solved:

Looks like there was a problem with my public key file. PuttyGen will create a public key file that looks like:

Comment: "rsa-key-20121022"

However, this will not work, so what you need to do is to open the key in PuttyGen, and then copy it from there (this results in the key being in the right format and in 1 line):

ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAhGF6GIuMY8FJ1+CNApnSY1N2YSlkYz72Yvwua6N1nFpBklz1+dsIMg4rcTLcF34M/tW5Yz+NUDAw2AEbxQ32FPgw7sAOIXktkYOHtr7mmimiTjkoSCrJh1kqalPSpi8rglT/Bp67Ql2SZwvUFfMzHISryR0EZC4rXP/uvObrJe8= rsa-key-20121022

Paste this into authorized_keys then it should work.

share|improve this answer
I opened authorized_keys in vi and removed all of the line breaks and it worked. – Luke Mar 13 at 19:59
where is the public key file located? i am only using putty. – Syler Mar 26 at 0:43

Just a tip I hope may help someone else with the headaches I had. F21 is right that you need to copy the key out of the PuTTYGen window instead of saving the file, but after copying, the way you paste may have significant impact on whether your key will work or not. Some editors will alter the text as you paste, or do something with newlines or something that makes the authorized_keys file invalid.

What I have found to be the least likely to break is to echo the full string and redirect the output to the file. Right-clicking in PuTTY to paste the key string to the commandline, it works out like this (with the example given above):

echo [right-click-to-paste-here] > /etc/ssh/username/authorized_keys

You'll end up with this:

echo ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAhGF6GIuMY8FJ1+CNApnSY1N2YSlkYz72Yvwua6N1nFpBklz1+dsIMg4rcTLcF34M/tW5Yz+NUDAw2AEbxQ32FPgw7sAOIXktkYOHtr7mmimiTjkoSCrJh1kqalPSpi8rglT/Bp67Ql2SZwvUFfMzHISryR0EZC4rXP/uvObrJe8= rsa-key-20121022 > /etc/ssh/username/authorized_keys

Another advantage of this method is that you can add multiple keys this way by using >> to append instead of > to overwrite, eg:

echo ssh-rsa AAAAB3<...snip...>rJe8= rsa-key-20121022 >> /etc/ssh/username

Hope that helps someone.

share|improve this answer
This don't work for 4096 bits exceeds the terminal limit for characters i think – Freedo Jul 18 '15 at 8:04


  1. You need to download the puttyGEN and generate a public and a private key.
  2. I've assigned a password to my private key.
  3. then configure the private key in putty. Putty->SSH->Auth->Browse to your private.
  4. Ensure you have the same path for private and public key.
  5. You need to configure the public key on the server. (In my case I've talked with the server guy and asked if he could add my public key to the server). You need the public key in the other side (server) the connection.
share|improve this answer

In my case the reason was that private key file (.ppk) had been removed in Putty authentication agent i.e. Pageant. I just updated it again to Pageant there and connection worked perfectly after that.

share|improve this answer

We were already using the right type of key (ppk instead of pem)..

In our case, it was a problem with the file permissions for authorized_keys on the server user folder. It has to be -rw-r--r-- ... It was -rw-rw-r--

ssh is very finicky about file perms.

share|improve this answer
  1. Edit the /etc/ssh/sshd_config file.
  2. Change PasswordAuthentication and ChallengeResponseAuthentication to yes.
  3. Restart ssh /etc/init.d/ssh restart.
share|improve this answer

protected by Eric Carvalho Aug 20 '15 at 11:14

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.