3

I am trying to set up a new user for my AWS EC2. I have followed step by step this tutorial but I get Permission denied (publickey) error.

I tried as well creating a newuser-key-pair.pem from AWS EC2 console and ssh -i newuser-key-pair.pem new-user@my-public-ip but it didn't work.

I think the problem is that I generated a key pair (private key) but the public key that I uploaded to the AWS .ssh/authorized_keys is not linked to it. How can I overcome this?

Arturo
  • 423
  • 3
  • 6
  • 20

2 Answers2

6

You can login to EC2 instance with the same access key you use for default user. Suppose, you are running Ubuntu and default username is ubuntu. Then your public key is located in /home/ubuntu/.ssh/authorized_keys

Create new user as described in AWS documentation and add public key to its ~/.ssh/authorized_keys. Now you should be able to login to you instance with original key pair.

lexsys
  • 2,913
  • 6
  • 31
  • 34
  • It is not recommended to share a single ssh private key between multiple users. This makes security more difficult and forces you to give sudo permissions to all your users. Cracking a private key's pass phrase should take only a few hours if one of your users is compromised – Chanoch Apr 26 '17 at 09:10
1

First Follow this to create and grant ssh permissions to new user.

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/managing-users.html

Your public key can be found under: /root/ssh/authorized_keys. Remember to also change ownership of the folder .ssh and the file authorized_keys. Change the ownership to the newly created user:

sudo chown newuser:newuser -R path to new user folder/.ssh

Replace newuser with whatever you called your new user

sebix
  • 4,313
  • 2
  • 29
  • 47