I cannot login to my user directly from SSH, `Permission denied (publickey).`.

May 14, 2017 199 views
Linux Basics Ubuntu 16.04

Hello I have been using DigitalOcean for couple of months for my Python Flask project. I usually starts my Droplet creation with these commands.

# In my local computer.
ssh root@
# In droplet.
adduser user_test
usermod -aG sudo user_test
su - user_test
# Logged in into user user_test.

I used DigitalOcean since last year November and then stopped using DigitalOcean for the last two months. I am pretty sure after the commands above I can directly connect into user user_test with this command.

ssh user_test@

However today login with such command now results in Permission denied (publickey).. If I want to login into user_test I need to login from root.

ssh root@
su - user_test

Is there any steps I missed those make me unable login directly to user?

1 comment
  • There may be some issues like:

    1. You are providing incorrect password
    2. Your user has been locked as password policy.
    3. Or your user is denied using ssh

    Please login with root user. Change your user password, then try to login using ssh with your User,

    I presume this will help you.

    Thanks in advance.

2 Answers


The Permission Denied (publickey) generally means that SSH Keys are enabled and when trying to login as user_test, the only accepted method of authentication is an SSH Key, which isn't provided via the command you're executing to login.

To pass an SSH Key during login, you need to pass the -i argument followed by the path to the key (private key) that's stored locally.

ssh user_test@111.222.333.444 -i /path/to/private_key

As root, I'd open up /etc/ssh/sshd_config, like so:

nano /etc/ssh/sshd_config

And search for PasswordAuthentication. If that's set to no, password-based logins won't work and only SSH Keys will be allowed to be used -- which would be a little odd if you're able to login as root without a key, if this is set to no.

When trying to login with user_test, you can pass -v, -vv, or -vvv to get a more verbose output as to what's going on to help identify the issue. You'd run that locally, for example, try:

ssh user_test@111.222.333.444 -v


ssh user_test@111.222.333.444 -vv


ssh user_test@111.222.333.444 -vvv

Hi @notalentgeek !

Check if you have permissions on ~/.ssh/authorized_keys with user_test. You can check them with the command ls -al and appears like this:

drwxr-xr-x 14 user_test staff 476 May 4 18:42 .atom
-rw------- 1 user_test staff 13461 May 14 21:26 .bash_history
-rw-r--r-- 1 user_test staff 18 May 4 17:13 .bash_profile
drwx------ 123 user_test staff 4182 May 14 21:46 .bash_sessions

If you don't have permission in the file you have to change file owner

chown user_test:user_test ~/.ssh/autorized_keys


Have another answer? Share your knowledge.