Create a sudo user on Ubuntu Linux

Help us grow :) Please share our articles for reach.

A sudo user is a regular user who has some admin rights to perform administrative tasks on the Linux system. In Linux, the super user ‘root’ has full admin rights, and therefore we do not give the root login to others to use on the system. The best practice is thus to give a normal Linux user Sudo privileges. This allows us to track which commands the user has executed, and what changes he has made to the system. These are logged in /var/log/auth.log .

While installing the Ubuntu Linux system the ‘sudo’ group is created automatically. By adding a user to this group, the user will have admin rights on the system, and can run administrative commands simply by starting them with ‘sudo’ and then authenticating.

Creating a Sudo user.

Open your terminal as root user and create the new user:

# adduser sudo-user

This command will prompt to set password for the new user, as well as some personal information. See the screenshot below:

You can confirm that the new user was added by using the ID command:

root@sleuthtechnical:~# id sudo-user
uid=1001(sudo-user) gid=1001(sudo-user) groups=1001(sudo-user)

This output confirms that the user was created successfully. Now we can add the user to the sudoers group by using the ‘usermod’ command:

# usermod -aG sudo sudo-user
# id sudo-user

The output should look like this:

We can test the sudo access for the new user by switching to it, and then running an admin command that requires sudo privileges.

# su - sudo-user
$ sudo apt update

The output should look like this:

As you can see, the ‘sudo-user’ was able to run the apt update command by preceding it with sudo. 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.

Sleuth

Sleuth has over 15 years experience in the hosted and cloud environment.

Leave a Reply