Create a new user on EC2 and give sudo privileges

Writing by on Monday, 2 of May , 2016 at 10:00 pm

Assumptions:
newhost.compute.internal is the new host you launched
ec2-user is the user created by EC2
newuser is the user you want created and need password-less ssh & sudo privileges
– id_rsa.pub is newuser’s public key

# Copy newuser’s id_rsa.pub to the new instance
scp -i ~/.ssh/my.pem ~/.ssh/id_rsa.pub ec2-user@newhost.compute.internal:~

# Login to the newhost (and sudo as root)
ssh -i ~/.ssh/my.pem ec2-user@newhost.compute.internal
sudo su –

# add newuser and copy the keys
useradd -c “firstname lastname” newuser
cd /home/newuser
mkdir .ssh
cat /home/ec2-user/newuser.pub >> .ssh/authorized_keys

# provide right ownership and permissions
chmod 700 .ssh
chmod 600 .ssh/authorized_keys
chown -R newuser:newuser /home/newuser

# give sudo access
vim /etc/sudoers
newuser ALL=(ALL:ALL) NOPASSWD:ALL

Leave a comment

Category: AWS

No Comments

No comments yet.

Leave a comment

You must be logged in to post a comment.

Shivdev Kalambi's Blog

Shivdev Kalambi is a Software Development Manager, previously a Principal Software Engineer at ArcSight/HP. With over 16 years' experience in software development, he's worked on several technologies and played different roles and contributed to all phases of projects. Non-tech activies include Ping-pong, Rock Climbing and Yoga at PG, Golf, Skiing, Swimming & a beer enthusiast.