I made a droplet with ssh keys selected, logged in as root perfectly fine, did “adduser demo” and “gpasswd -a demo sudo”. When i try to ssh in as demo@xxx.xxx.xxx i get a “Permission denied (publickey).” but when i try again as root@xxx.xxx.xxx its perfectly fine.

1 comment
  • Most of the answers are outright wrong.

    What you need is to add the ssh key to your non-root account. Since you already have ssh keys in root’s user directory. All you need is to execute this command:

    rsync --archive --chown=non_root_user:non_root_user ~/.ssh /home/non_root_user
    

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.

×
1 answer

Hi @CrustyWang69

You need to edit the file /etc/ssh/sshd_config and edit/add this line:

PasswordAuthentication yes

And restart sshd with the command sudo service ssh restart

  • @hansen thanks that worked but how do i login using ssh key? i can login with ssh key as root but have to use password as the other user?

    • Your sshd_config should now have these two lines (probably different positions)

      PasswordAuthentication yes
      PubkeyAuthentication yes
      

      First line allows passwords, second line allows keys.

    • @hansen nvm i figured it out apparently you need to add the key again loggin in as new user like so “ssh-copy-id newuser@host” the ssh key you use at droplet creation is for root only apparently

      • @CrustyWang69

        Ahhh, sorry, I misunderstood your question then. I thought that you wanted to be able to login with password. Someone just asked that question a few minutes before.

        I would highly recommend only using keys and disabling the password access for all users.

Submit an Answer