How to create a sudo user on Ubuntu Linux

In this post, we will show you how to create a sudo user on Ubuntu Linux.

Sudo user is a regular user in Linux who has some admin rights to perform administrative task on the system. In Linux, root is the super user who has full admin rights, but it not recommended to give root credentials other users or to work on a system as root user.

So, the best practice is to create a regular user and assign sudo rights.  By doing so we can track which user has executed which commands using sudo logs (/var/log/auth.log).

When we install Ubuntu Desktop or Ubuntu server then a group named ‘sudo’ is created automatically. If we add any regular user to that sudo group then that user will have sudo admin rights.

Creating Sudo User from Command Line

In this post, we have tested following commands on Ubuntu 22.04 LTS (Jammy Jellyfish). To create new sudo user, open the terminal and switch to root user and run following command,

# adduser <user-name>

Example,

# adduser sysops

This command will prompt to set password of sysops user and other details as shown below,

adduser-command-ubuntu-linux

Output of id command confirms that sysops user is created successfully, now add this user to sudo group using usermod command,

# usermod -aG sudo sysops
# id sysops

Output,

Adduser-sudo-group-ubuntu-linux

To add an existing user to sudo group, run

# usermod -aG sudo <<Exiting-User-Name>>

Testing Sudo User Access

To test sudo access, switch to sudo user and try to run some admin commands by placing sudo in front of command.

# su – sysops
$ sudo ls -l /root
$ sudo apt update

Testing-Sudo-Access-Ubuntu-Linux

As we can see above, sysops user is able to run admin commands by putting sudo in front of each command. When we run the command with sudo first time then it will prompt you to enter user’s password and will save it for next 5 minutes. After that interval, it will prompt to enter password again while executing sudo command.

Creating new sudo user from Desktop Environment (GUI)

If you are not comfortable with command line and wants to create a new sudo user from GUI then refer the below steps.

From the Activity, search users and click on user’s icon as show below,

Search-Users-Activity-Ubuntu-Desktop

It will take us to the following window, click on unlock and enter your user’s password,

unlock-to-add-user-ubuntu-desktop

After entering the credentials, click on Add User option and specify the user details like full name, username, standard or administrator (sudo) and password.

Add-User-Details-Ubuntu-Linux

Click on Add,

Sudo-User-Details-Ubuntu-Desktop

Great, above window shows that sysops user is created as a sudo user (administrator). To start using this user, logout and login with this user.

That’s all from this post. we hope you have learnt how to create a sudo user on ubuntu Linux from command line and desktop environment (GUI). Please don’t hesitate to post your queries and feedback in below comments section.

Leave a Comment