How to Add User To Sudo Group on Ubuntu
Posted on 12 Oct 2021
Photo by Gabriel Heinzer
TLDR;
Create a new user:
adduser <username>
Add a new user to sudo group:
usermod -aG sudo <username>
Create A New User To The System
-
Log in to your server as the root user.
ssh root@server_ip_address
-
Use the
adduser
command to add a new user.# replace the <username> adduser <username>
-
You will be prompted to create and verify a password for the user.
Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
-
Next, you’ll be asked to fill in some information about the new user. It is fine to accept the defaults and leave this information blank.
Changing the user information for <username> Enter the new value, or press ENTER for the default Full Name []: Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n]
Adding the User to the sudo Group
Next, use the usermod
command to modify a user account and add the user to the sudo group.
# replace the <username>
usermod -aG sudo <username>
The -aG
option tells the system to append the user to the specified group. In this scenario we are appending the user with username: <username>
into the sudo
group.
Verify sudo Access
To test that the new sudo
permissions are working, run the su
command to switch to the new user account and you’ll be prompted to enter the user password.
# replace the <username>
su - <username>
For example:
root@vm:~# su - <username>
Password:
<username>@vm:~$
Notice the user has changed. Now, try to list the directory of the /root
directory, which is normally only accessible to the root
user.
Note: The first time you use sudo in a session, you will be prompted for the password of that user’s account.
sudo ls -la /root
[sudo] password for <username>: