This is a quick guide on how to create a new sudo user on Ubuntu. As you probably already know, sudo is a useful command that grants administrator privileges to the current user. If a user isn’t root and they aren’t present in the sudoers file, then they will be unable to carry out a number of important actions.
In fact, they won’t be able to do much at all.
Step 1. Make sure that you have sudo privileges.
This may seem obvious but I will state it anyway.
To create a new sudo user, you must be logged in as root or as an existing sudo user. To sum it up: If you don’t have administrative privileges, then you will be unable create a sudo user.
Step 2. Create the new user.
To create the new user, simply enter the following command:
sudo adduser wayne
Above, I used the adduser command to create a new Ubuntu user called wayne. After you enter this command, you will be prompted to fill out details about this new user.
Step 3. Add the new user to our sudoers list.
To add the user to your sudoers file, we will use the usermod command:
sudo usermod -aG sudo wayne
By adding the user to the sudo group, we have automatically given them sudo privileges.
Step 4. Test it.
To test the sudo privileges of our new user, we will need to switch accounts:
su - wayne
Note that the hyphen is important as it tells Ubuntu that you want to adopt the environment of the user in question.
Once you have successfully switched accounts, you can test out the sudo privileges by creating a test file:
sudo touch /home/wayne/test.txt
Once you run the command above, you should be greeted with the following sudo password prompt:
[sudo] password for wayne:
That’s it! Enter your password and the command should run under sudo privileges. If it doesn’t, it means that you have probably messed up one of the steps above.