How to create a sudo user on Ubuntu

March 16, 2022 No comments ubuntu sudo create adduser

1. Introduction

In this short tutorial, we will learn how to create a new user on Ubuntu with sudo privileges. With sudo, we could grant administrator privileges to not root users in Linux OS. This guide will show simple steps to create a new user and add them to sudo group.

2. Steps to create a sudo user on Ubuntu

2.1. Log in to your local or remote server:
ssh admin@server_ip_address
2.2. Use adduser command to create new user

If you are not the root user use sudo before adduser command:

sudo adduser username

Replace username with the user that you wish to create.

If you use sudo command you will be prompted to provide the password.
[sudo] password for admin:
Next, you will need to confirm the new user’s password at the prompt.
New password: 
Retype new password: 
passwd: password updated successfully
Next, fill all prompts with new users' information or leave all of these fields blank.
Enter the new value, or press ENTER for the default
    Full Name []: 
    Room Number []: 
    Work Phone []: 
    Home Phone []: 
    Other []:
Confirm the correctness of the information you provided and we are almost there.
Is the information correct? [Y/n] y
2.3. Finally, use the usermod command to add the user to the sudo group.
sudo usermod -aG sudo username

3. Test sudo user

3.1. Switch to a new user using su command
su - username
3.2. Now as a new user check if you could use sudo to run commands with superuser privileges.

For example, you could list the root user directory.

sudo ls /home/root
3.3. If this is your first use of sudo in a console session, you will be prompted for the password. Enter the password to proceed.
[sudo] password for username:

4. Conclusion

In this short tutorial, you learn how to create a new user on Ubuntu OS with sudo. By default, members of the sudo group have sudo privileges, so all we need to do after creating a new user is to assign them to sudo group.

{{ message }}

{{ 'Comments are closed.' | trans }}