1

I recently made some new users in my digitalocean droplet, and I would like to access them directly with the command ssh username@ip. However, I get denied with username@ip: Permission denied (publickey). For clarification, the machine has the correct private-key and can access the droplet with ssh root@ip

I did the following to create the new user

root@school:~# adduser username
Adding user `username' ...
Adding new group `username' (1001) ...
Adding new user `username' (1001) with group `username' ...
Creating home directory `/home/username' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

After these steps, what is further to do to be able to access the droplet with ssh username@ip ?

  • if available you could use the tool ssh-copy-id username@ip to copy the PUBLIC key to the authorized_key file from the user on the server – Dennis Nolte Mar 20 at 16:44
5

"the machine has the correct private-key"

That is the root cause of your misunderstanding. Access is controlled separately for each account, not for the machine as a whole.

For each account you want to access with a particular key you will need to append the associated public key to the file ~/.ssh/authorized_keys in the home directory of that account.

Or in other words: copy /root/.ssh/authorized_keys to /home/username/.ssh/authorized_keys and ensure the correct ownership and permissions on those files/directories.

  • 1
    while true please note that you will copy the PUBLIC key, not the private key into the authorized_keys. Additionally copy might just overwrite and give too much access so be catious when doing a copy. – Dennis Nolte Mar 20 at 16:44
  • It would be simpler using the ssh-copy-id tool: ssh-copy-id user@remote-host – JucaPirama Mar 21 at 14:21
  • @JucaPirama ssh-copy-id user@remote-host leaves you in a bit of a catch-22 when your SSHD configuration does not allow password authentication (which is quite strongly recommended). – HBruijn Mar 21 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.