[SOLVED] SSH PubkeyAuthentication not working

Just installed DietPie on my rpi 3.
I followed documentation switching from dropbear to openssh in the first boot installation.

Now I want disable password logins on ssh, and I’ve uploaded my pub key (already generated) creating authorized_keys file under ./ssh folder.

Then chmod 600 and chown dietpi:dietpi on the authorized_keys file.
Restarted sshd service.

Attempting to ssh with private key I get "‘Server refused our key’’ and I’m, able to login with password only.

Are you sure you are using the correct private key on your SSH client?

Yes, I’m using the same pair of keys that was working on the previous raspbian os lite installation.

did you already tried following already?

sudo chmod 700 /home/dietpi/.ssh
sudo chmod 600 /home/dietpi/.ssh/authorized_keys
sudo chown dietpi:dietpi /home/dietpi/.ssh/authorized_keys

as well, you are sure the key has been copied correctly into /home/dietpi/.ssh/authorized_keys (assuming you login as user dietpi)?

1 Like

Solved.
Issue was the format of the pubkey in the authorized_keys file.

I changed from:

---- BEGIN SSH2 PUBLIC KEY ----
Comment: "blablabla"
AAAADAQABAAABA...............
---- END SSH2 PUBLIC KEY ----

To (in one line):
ssh-rsa AAAADAQABAAABA............... user@hostname

yes correct, it needs to a one-liner. :+1: