Create a new user on EC2 and give sudo privileges
Writing by shivdev 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
- Add this post to
- Del.icio.us -
- Digg -
- -
- Tweet -
-
-