Create a New Sudo User in AWS EC2
(Ubuntu AMI)
Log in your Ec2 Instance using “ec2-user”
ssh ec2-user@ -i
Log in to your server as the root user.
ubuntu@ip-172-31-24-53:~$ sudo -i
root@ip-172-31-24-53:~#
Use the adduser command to add a new user to your system.
adduser
root@ip-172-31-24-53:~# adduser test
Set and confirm the new user’s password at the prompt. Use
strong password to secure account
root@ip-172-31-24-53:~# passwd test
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Use the usermod command to add the user to the sudo group.
usermod -aG sudo username
root@ip-172-31-24-53:~# usermod -aG sudo test
By default, on Ubuntu, members of the sudo group have sudo privileges.
Test sudo access on new user account
Use the su command to switch to the new user account.
root@ip-172-31-24-53:~# su test
su - username
As the new user, verify that you can use sudo by prepending “sudo” to the command
that you want to run with superuser privileges.
test@ip-172-31-24-53:/root$ sudo ls -la /root