Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to add a user to my AWS instance and ssh in as that user with the existing keypair.

Right now I can log into my AWS instance as root:

ssh -i ~/path/mysshkeypair.pem

Logged in as root, I created another user and gave it a home directory. I can type "su otheruser" and navigate around. But when I exit back to my machine and try:

ssh -i ~/path/mysshkeypair.pem

I get: Permission denied (publickey).

What steps do I need to follow to be able to log in as otheruser?

My machine is a Mac and the instance is an Ubuntu machine.

share|improve this question

I'm assuming you are using a unmodified SSH configuration.

You are trying to use the same private SSH key with different Ubuntu users. However, the SSH server on the Ubuntu machine will try to find the matching public SSH key in the home directory of the login user only, i.e. 'otheruser' in your case, and you apparently haven't supplied the public SSH key in question there as well.

You can make this work by appending the public SSH key(s) of user 'root' (usually contained in /root/.ssh/authorized_keys) to those of user 'otheruser' (usually contained in /home/otheruser/.ssh/authorized_keys), i.e. in your case you can likely just copy the former to the latter.

Please note that in case your SSH server configuration has been hardened already, there might be additional adjustments needed to enable SSH access for 'otheruser' in the first place (e.g. appending 'otheruser' the AllowUsers directive within /etc/ssh/sshd_config), however, this would be unusual for any default AWS Ubuntu instance.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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