Development notes

Thoughts, notes and ideas about development

How to fix Permission denied (publickey) error

2021-07-17 1 min read Linux

This blog post describes how to fix “Permission denied (publickey)” error while logging in via ssh using a public key.

Ensure you have access to the server via Web console, like Quemu Terminal on Digital Ocean, or have physical access to the server.

Connect to your service via Web console or with a keyboard.

Update ssh config file to allow password authentication:

Open the file:

sudo vim /etc/ssh/sshd_config

Replace PasswordAuthentication no to PasswordAuthentication yes

Updated config file should look like this:

s-tui

Save the file and reload ssh config:

sudo service sshd reload

Upload ssh public key from the terminal you’ve tried to connect via ssh:

ssh-copy-id username@server-ip

Make sure username and service-ip are replaced by relevant values

Connect to remote server:

ssh username@server-ip

Now we can disable password authentication by replacing PasswordAuthentication yes back to PasswordAuthentication no. Do not forget to reload ssh config file:

sudo service sshd reload
comments powered by Disqus