I have a 12.10 server setup in a virtual machine with its network phối to lớn bridged (essentially will be seen as a computer connected to lớn my switch).

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

I then phối about trying to lớn get it to lớn use public/private key authentication. I did the following:

  1. Generated the keys using PuttyGen.
  2. Moved the public key to lớn /etc/ssh/myusername/authorized_keys (I am using encrypted trang chính directories).
  3. Set up sshd_config lượt thích 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 lập cập sshd in debug mode, I see:

PAM: initializing for "username"
PAM: setting PAM_RHOST to lớn "192.168.1.7"
PAM: setting PAM_TTY to lớn "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 tệp tin /usr/share/ssh/blacklist.RSA-1023
Checking blacklist tệp tin /etc/ssh/blacklist.RSA-1023
temporarily_use_uid: 1000/1000 (e=0/0)
trying public key tệp tin /etc/ssh/username/authorized_keys
fd4 clearing O_NONBLOCK
restore_uid: 0/0
Failed publickey for username from 192.168.1.7 port 14343 ssh2
Received disconnect from 192.168.1.7: 14: No supported authentication methods available [preauth]
do_cleanup [preauth]
monitor_read_log: child log fd closed
do_cleanup
PAM: cleanup

Why is this happening and how can I fix this?

Eric Carvalho

55.1k104 gold badges142 silver badges163 bronze badges

asked Oct 22, 2012 at 1:10

2

Problem solved:

Looks lượt thích there was a problem with my public key tệp tin. PuttyGen will create a public key tệp tin that looks like:

---- BEGIN SSH2 PUBLIC KEY ----
Comment: "rsa-key-20121022"
AAAAB3NzaC1yc2EAAAABJQAAAIEAhGF6GIuMY8FJ1+CNApnSY1N2YSlkYz72Yvwu
a6N1nFpBklz1+dsIMg4rcTLcF34M/tW5Yz+NUDAw2AEbxQ32FPgw7sAOIXktkYOH
tr7mmimiTjkoSCrJh1kqalPSpi8rglT/Bp67Ql2SZwvUFfMzHISryR0EZC4rXP/u
vObrJe8=
---- END SSH2 PUBLIC KEY ----

However, this will not work, ví what you need to lớn bởi is to lớn 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.

answered Oct 22, 2012 at 1:47

10

  1. Edit the /etc/ssh/sshd_config tệp tin.
  2. Change PasswordAuthentication and ChallengeResponseAuthentication to lớn yes.

3a. Restart ssh /etc/init.d/ssh restart.
OR
3b. better you use service sshd restart

answered Aug 19, năm ngoái at 12:35

5

Just a tip I hope may help someone else with the headaches I had. F21 is right that you need to lớn copy the key out of the PuTTYGen window instead of saving the tệp tin, 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 bởi something with newlines or something that makes the authorized_keys tệp tin invalid.

What I have found to lớn be the least likely to lớn break is to lớn echo the full string and redirect the output to lớn the tệp tin. Right-clicking in PuTTY to lớn paste the key string to lớn the commandline, it works out lượt thích this (with the example given above):

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

You'll over 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 lớn append instead of > to lớn overwrite, eg:

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

Hope that helps someone.

answered Feb 27, 2013 at 1:04

4

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

In our case, it was a problem with the tệp tin permissions for authorized_keys on the server user thư mục. It has to lớn be -rw-r--r-- ... It was -rw-rw-r--.

SSH is very finicky about tệp tin perms.

Check tệp tin permissions using:

ls -l authorized_keys

You can fix them if necessary with:

chmod 644 authorized_keys

matigo

23.9k7 gold badges47 silver badges78 bronze badges

answered Mar 13, năm ngoái at 18:50

6

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

answered Jan 17, năm trước at 17:58

SOLVED:

  1. You need to lớn tải về the puttyGEN and generate a public and a private key.
  2. I've assigned a password to lớn my private key.
  3. then configure the private key in putty. Putty->SSH->Auth->Browse to lớn your private.
  4. You need to lớn 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 lớn the server). You need the public key in the other side (server) the connection.

answered Apr 17, 2013 at 9:38

1

You must log in to lớn answer this question.

Not the answer you're looking for? Browse other questions tagged

.