gauss76
Posts: 13
Joined: Fri Feb 22, 2013 12:32 pm

Jessie Login with SSH keys from PuTTY not working

Sun Feb 05, 2017 8:54 pm

Hi,

I have now been using Pi Jessie for a few months now headlessly. I connect to the pi on my local network via SSH password with PuTTY from a windows 10 64-bit machine. I recently tried to set up SSH key authentication but cannot get it to work. I generated the key pair with PuTTYgen. I then appended the public key to the file /home/pi/.ssh/authorized_keys. I then restarted ssh on the pi with

sudo /etc/init.d/ssh restart

Next, on my Windows machine, I ran Pageant and added my Private key, entering the password when prompted. Finally I ran PuTTY making sure that it pointed to my private key on the windows system.

However, each time I try and connect I get the usual password prompt.

If I go into the file /etc/ssh/sshd_config and set PasswordAuthentication no then I can no longer login to the Pi from my windows PC.

I also have an Android phone with JuiceSSH installed. With this I can access my Pi using keys. I have the public key in the Pi's authorized_keys file and if I set PasswordAuthentication no in /etc/ssh/sshd_config everything works fine.

In conclusiuon I have no idea why the JuiceSSH system works and not the Putty version.

I have tried both public keys in the authorized_keys file and each individually. But the JuiceSSH key is the only one that ever works!

Any help much appreciated.

gauss76

User avatar
allfox
Posts: 452
Joined: Sat Jun 22, 2013 1:36 pm
Location: Guang Dong, China

Re: Jessie Login with SSH keys from PuTTY not working

Mon Feb 06, 2017 10:29 am

gauss76 wrote: Finally I ran PuTTY making sure that it pointed to my private key on the windows system
Greetings.

Could you explain how did you direct PuTTY to point to key?

My experience tells me PuTTY in default setting would work OOTB. When publickey and password are both available, it would try publickey first.

So I'm guessing: Pagent and PuTTY need to be running at the same time. Don't close Pagent.

If possible, please post some output from the system. I know the system is not working, I need to know the error output to find a solution. When there is only publickey enabled on Pi, and the PC can not provide a key, PuTTY would show a dialog when connecting: No athentication method available( server sent: publickey ). Did you see something like that? Or what did you see when connecting?

gauss76
Posts: 13
Joined: Fri Feb 22, 2013 12:32 pm

Re: Jessie Login with SSH keys from PuTTY not working

Tue Feb 07, 2017 10:24 pm

Hi,

Many thanks for the quick reply. I am currently very busy at the moment. I'll try and post a reply answering your questions in the next couple of days.

gauss76

gauss76
Posts: 13
Joined: Fri Feb 22, 2013 12:32 pm

Re: Jessie Login with SSH keys from PuTTY not working

Sat Feb 11, 2017 4:41 pm

OK, I now have a bit of time. This is how PuTTY is configured. On the left hand side there is an category under Connection->SSH->Auth (Screenshot attached). That is where I put the path for my privatekey file. It also has a tickbox for use of Pageant.

Now before running PuTTY I open Pageant and add my privatekey file and enter the associated passphrase. The privatekey is then added to Pageant with no problems.

Finally I run PuTTY and try and connect to the Pi. On the Pi, if password authentication is enabled (PasswordAuthentication yes) in the file

/etc/ssh/sshd_config

and I try and connect with keys I get the following message:

Using username "pi"
Server refused our key
then I get prompted for my SSH password.

On entering the password I have SSH access, but not with keys.

Now setting PasswordAuthentication no in the file /etc/ssh/sshd_config and trying to connect with PuTTY/Pageant I get the windows error dialogue box with heading: "PUTTY Fatal Error" containing the following message:

Disconnected: No supported authentication methods available (server sent: publickey)

Please let me know if you require any further information.

gauss76
Attachments
PuTTY_Pi_SSH.gif
PuTTY_Pi_SSH.gif (18.5 KiB) Viewed 3387 times

Ernst
Posts: 1334
Joined: Sat Feb 04, 2017 9:39 am
Location: Germany

Re: Jessie Login with SSH keys from PuTTY not working

Sun Feb 12, 2017 4:31 pm

Have you looked at ~/.ssh/authorized_keys to see that the public key is correctly formatted ?
The road to insanity is paved with static ip addresses

User avatar
allfox
Posts: 452
Joined: Sat Jun 22, 2013 1:36 pm
Location: Guang Dong, China

Re: Jessie Login with SSH keys from PuTTY not working

Sun Feb 12, 2017 4:58 pm

Ernst wrote:Have you looked at ~/.ssh/authorized_keys to see that the public key is correctly formatted ?
I suggest OP directly post authorized_keys file here, as it's the public key in it, there should be no security problem.

Anyway, a single bing search on "Server refused our key" tell me this: http://www.walkernews.net/2009/03/22/ho ... ublic-key/

We need a key start with "ssh-rsa" in authorized_keys file, not "---- BEGIN SSH2 PUBLIC KEY ----".

gauss76
Posts: 13
Joined: Fri Feb 22, 2013 12:32 pm

Re: Jessie Login with SSH keys from PuTTY not working

Sun Feb 12, 2017 8:31 pm

Fantastic! That was the solution...Basically the public key generated by PuTTYgen is not recognized, as is, if pasted into the pi's authorized_keys file. Editing it as outlined in the link provided by allfox solves my problem.

Many thanks to all who commented on my post, much appreciated.

gauss76

broe23
Posts: 903
Joined: Thu Jan 28, 2016 9:35 pm
Location: Central IL
Contact: Website

Re: Jessie Login with SSH keys from PuTTY not working

Sun Feb 12, 2017 11:01 pm

Also remember that if the keys do not work, delete them on your machine that you are using for remote connection and then when you get the new one from OpenSSH, it should connect.
Ren: Now listen, Cadet. I've got a job for you. See this button? Ren: Don't touch it! It's the History Eraser button, you fool! Stimpy: So what'll happen? Ren: That's just it. We don't know. Maybe something bad, maybe something good.

Return to “General discussion”