I can use ssh -i ~/.ssh/id_rsa root@SERVER to connect to my Ubuntu VM but I have another user in same VM and I would like to connect directly to it. I tried ssh -i ~/.ssh/id_rsa newuser@SERVER but I get this error: Permission denied (publickey)

  • 1
    Does the other user have the correct public key in their ~/.ssh/authorized_keys file?
    – Kusalananda
    Jul 25 at 8:37
  • 1
    @Kusalananda it was empty, I added the public key to it and it working fine now, Thanks
    – awabs
    Jul 25 at 8:52

The issue is likely that the non-root user on the server does not have a ~/.ssh/authorized_keys file, or that it does not contain the correct public SSH key. Copying the correct public SSH key to that file should make the login over SSH work.

Related: Add a public ssh key to the authorized_keys of a user

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.