Create New User on Amazon AMI and Give It Root Access

Setup your new EC2 instance on AWS and choose Amazon AMI.

SSH to your instance using your private key

1
ssh -i <path-to-your-pem-file> ec2-user@<ec2-endpoint-or-ip>

Change to root

1
sudo su

Create new group for your user ( in this case my group name is ‘dev’ )

1
groupadd dev

Create new user and assign it to your recently created group

1
useradd -g dev dev

Give the username root access

1
visudo

Add this to the bottom of the file

1
dev     ALL=(ALL)       NOPASSWD:ALL

Delete the password for ‘dev’ user

1
sudo passwd dev -d

Change to the ‘dev’ user

1
su dev

Try run sudo su whether you can gain root privileges

1
sudo su

Change user back to dev and set authorized_keys for ssh

1
2
3
4
exit
mkdir ~/.ssh
vi ~/.ssh/authorized_keys
chmod -R 700 ~/.ssh

If everything is correct, you should be able to change to root user from dev without providing any password.

Comments