Permission denied (publickey)

Hey guys,

I've followed the security guide in the library and locked down my server to only allow access with SSH keys. Unfortunately due to me messing about, I now can't log in via SSH and get the message "Permission denied (publickey)."

I've generated a new local key and tried to upload it to the server but got the Permission denied message again.

Any ideas?



6 Replies

The .pub version of the key needs to have its contents entered in your server's /home//.ssh/authorized_keys file.

Can I just copy and paste it? I'm trying to upload the key via SCP but that's failing.

You should be able to use Lish, get an ssh session then edit the authorized_keys file with like vi or nano. It works for me. Then you should be able to ssh into your server as normal.

So cat the contents of *.pub then edit it into your authorized_keys over Lish or maybe the AJAX console since you can't log into your server normally until you get this fixed.

Nope, no joy. Copy and pasted the key across but still can't log in :(

Did you add an AllowUsers line to /etc/ssh/sshd_config ut forgot to add your account? Check /var/log/auth.log and messages.log for clues.

Make sure you are using the correct remote user:

ssh user@host

Also add the -v to get more information.

Make sure your /home//.ssh directory has proper permissions, 600 should be fine. Perhaps 640.

If you generated the keys on a Windows client using Cygwin in a bash shell, make sure the key files private and public are at 600 too.

Sorted now - I didn't realise I needed to restart ssh after editing the config :oops:

Thanks for your help though :)


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct