1

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 root@EC2-my###-###.compute-1.amazonaws.com

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 otheruser@EC2-my###-###.compute-1.amazonaws.com

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.

Jorge Castro
  • 71,754

1 Answers1

1

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.