Cannot login to server as non-root user (Permission denied (publickey))

I have created a Droplet and connect to it passwordless via SSH as root. While logged in as root, I created a new user ‘deploy’ which I want to use to deploy my app.

But, when I try to ‘ssh deploy@ipaddr’ I get this error message: Permission denied (publickey).

I’m guessing it’s trying to authenticate with my root key instead of asking me for the deploy users password. How can I get around this little issue?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

HI @nolyoi,

By default, the servers in DigitalOcean come with Password Authentication disabled. In this regard, when creating a new user, it would be best to create a home directory for it as well. In that home user directory, you can add your SSH key.

Another solution would be to enable password authentication and you would be able to ssh to the user with the password you’ve set it up for. Let me know which of the two you would prefer more and I’ll provide you with detailed steps.

Regards, KFSys

I guess that you have not properly configure SSH access for the deploy account. Assuming that you use the same computer (or the same private key) to connect to the deploy and root accounts on your server. You must add the corresponding public key to the ~/.ssh/authorized_keys file of your deploy account. After logging in to your root account, run the following command:

  1. rsync --archive --chown=deploy:deploy ~/.ssh/authorized_keys /home/deploy/.ssh

Then, you can login the deploy account with ssh deploy@ipaddr

You may read this tutorial for more information: Initial Server Setup with Ubuntu 20.04. It contain links for other operating systems too.