How to Create a Sudo User in Ubuntu? [Simplest Way]

A sudo user refers to a standard user with some elite powers. On the contrary, a regular user has some limitations like executing special operations or accessing some files from the root directory, etc. Sudo short for Super User does let one do some of these privileged tasks. In this article, I will guide you through the simple steps to create a sudo user in Ubuntu.

To create a sudo user in Ubuntu, check the following steps:

  1. Create a new user using the command:  sudo adduser [name_of_user]
  2. Add new user to sudo group: sudo usermod -aG sudo [name_of_user]
  3. Confirm User belongs to the Sudo group: groups [name_of_user]
  4. Check Sudo access of a new user:

a. Switch to new user: su - [name_of_user]

b. Verify sudo access: sudo whoami

What is a Sudo User in Linux?

A sudo user is the supreme user of the Linux-based machines. Because being a sudo user means having some distinctive powers compared to regular users. A sudo user can perform specialized tasks and access root-level contents.

4 Steps to Create a Sudo User in Ubuntu

In the following section, I will create a new sudo user named “simpsons” in Ubuntu. Here is the full process to create and verify a sudo user in 4 simple steps:

1. Create a New User in Ubuntu

To create a new user from the terminal, use the adduser command. Here is how:

  1. First launch a Ubuntu Terminal by pressing CTRL+ALT+T.
  2. Insert the following command to create a user:
    adduser simpsons
    EXPLANATION
    • adduser: Adds a new user.
    • simpsons: Creates a new user named simpsons.

    Using the adduser command to create anew user in Ubuntu.

  3. You have to be a root user to execute the adduser command. You can easily do this by using the following command:
    sudo adduser simpsons

    Here the sudo command grants administrative privileges.

    Using the adduser command with sudo to create anew user in Ubuntu.

  4. Now, provide a password for the newly created user and retype it. Here, You can skip the data-filling step by pressing ENTER each time and finally press Y to confirm.Steps of creating a new user.
  5. Finally, you can check whether the user has been created or not by running the following command:
    getent passwd | grep simpsons
    EXPLANATION
    • getent: Looks into the administrative database that is given as its argument.
    • passwd: Contains user information.
    • Pipe (|): Redirects the standard output.
    • grep: Looks for a specific pattern given to it as an argument.

    Checking whether the new user has been created.

2. Add the New User to the Sudo Group in Ubuntu

By default, a new user is added to a group named on the username itself. However, most of the Linux distributions as well as Ubuntu contain a group named “sudo”. Adding a user to this sudo group means this user will now possess privileged powers.

To add the newly created user to the sudo group, use the usermod command with option -aG. Run the following command:

sudo usermod -aG sudo simpsons
EXPLANATION
  • usermod: Modifies an existing user account.
  • -aG: Adds a user to the specific group.

Adding the new user to the sudo group in Ubuntu.



3. Confirm Whether the New User has been Added to the Sudo Group

To check whether the newly created user has been added to the sudo group or not, type the groups command followed by the group name:

groups simpsons

Here the groups command displays the user’s groups.

Checking whether the new user has been added to the sudo group.

4. Check Sudo Access of the New User

To check whether the user has sudo access, follow the below steps:

  1. Type the following command:
    su - simpsons

    Here su - command supersedes the current user sowad and switches it to simpsons as a root.Switching to new the newly created sudo user named "simpsons" in ubunru.

  2. Then, execute the sudo whoami command.Confirming wheher it is sudo user or not.
  3. Check whether it can access the root directory by copying the following command:
    sudo ls /root
    EXPLANATION
    • ls: Shows the lists of contents of the current directory.
    • /root: Directory Name.

    Accesing the root folder with the newly created sudo user in ubuntu.



Check If a User is a Sudo User in Ubuntu

You can inspect whether a user is a sudo user or not by using the following command:

sudo -l -U USERNAME

In the following image, I have examined two users named “softeko” & “simpsons” respectively. Between them, softeko was not a sudo user but simpsons was.

Checkinh if a user is a sudo user or not.

List Sudo Rights For a User in Ubuntu

You can list the rights of a sudo user by simply typing the below command:

sudo -l

In the following image, I have printed the rights of the sudo user named “simpsons” using the sudo command with the -l option.

Listing the rights of the sudo users.



Edit Sudoer File in Ubuntu

The sudo command can be modified by configuring the sudoer file located in the /etc directory. To edit the file you have to use the visudo command.

Note: Never edit the /etc/sudoer file with any normal text editors rather than the visudo command. Otherwise, it may break the sudo configuration.

To edit sudoer file in Ubuntu, run the following command in the command prompt:

sudo visudo

In the following image, you can see that the sudoer file has been opened in an editor (In Ubuntu it is nano). The main benefit of using the visudo command instead of using a normal text editor is that It will analyze the syntax while saving.Configuring the sudo command by modifying the sudoer file.

Conclusion

The concept of sudo user emerged from the idea of stopping adversarial operations exerted on the root systems. However, to exercise privileged powers you might require the proficiency to create a sudo user in Ubuntu. Hope this quick and clear guide will help you to be privileged!

People Also Ask

What can a sudo user do?

A sudo user can do things like install or remove software, change system settings, and manage user accounts. This is because sudo users have the power to do things that regular users can’t, which helps keep the system safe by blocking access to important stuff.

Is a sudo user a root user?

No, there is a subtle difference between the two. A sudo user is privileged but not as much as the root user. While a root user has unrestricted access to all system resources and commands, a sudo user is a regular user account with the privilege to execute specific commands with superuser (root) privileges.

Where is the sudo users list?

You can locate the list of sudo users in the /etc/sudoers file. You can also get the list of sudo users by checking the members of the sudo group, by running the command getent groups sudo | cut -d -f4.

Why is it called sudo?

Since it is the abbreviation of super user do or substitute user do. The term ‘sudo’ combines the first two letters of ‘superuser’ and ‘do’ to emphasize its primary function: executing commands with superuser privileges. This allows authorized users to perform administrative tasks, such as system configuration or software installation while maintaining security by restricting access to only those who need elevated permissions.

Is sudo a vulnerability?

No, sudo is not a vulnerability itself. However, it is important to configure it in a way that restricts access to commands and users with higher privileges to reduce potential security risks. To ensure a secure system, it is essential to adhere to best practice access control and to regularly review and audit the configuration of sudo.

Is sudo a security risk?

Sudo can be a security risk if used incorrectly. It gives privileged access to users and if configured incorrectly or misused, it can result in unauthorized access or unintentional system changes. To limit potential security risks, it is important to configure properly, perform regular audits, and restrict sudo access to critical commands and users.

Why use sudo instead of root?

For greater security and accountability, we prefer Sudo over direct root access. With Sudo, users can execute specific commands with higher privileges, minimizing the chance of accidental system changes. Sudo also offers a centralized logging mechanism that allows administrators to monitor and review user activity, improving system auditability.

What is sudo hack?

A sudo hack is when someone tries to control systems using the ” sudo” command in Linux. It’s when someone takes advantage of a vulnerability to get higher privileges and run commands with admin rights. This is illegal and can lead to data leaks or system damage. To protect your system, make sure you take the right cybersecurity precautions and update your system regularly to reduce the risk of a sud hack.

Should sudo require a password?

Yes, sudo needs validation with the user password before executing a command, and the default timeout of this password is 15 minutes. This helps prevent unauthorized access and strengthens overall system security.

Relaed Articles

5/5 - (3 votes)
LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now
icon linux
Md. Ashakul Islam Sowad

Hi, I am Md. Ashakul Islam Sowad from Dhaka, Bangladesh. I have completed my undergraduate degree in Biomedical Engineering from the Bangladesh University of Engineering and Technology (BUET). I love to watch football and play video games in my free time. Here, I am working as a Linux Content Developer Executive. Furthermore, as a Linux enthusiast, I am always learning new things about Linux-based systems and I’ll be sharing them here. Read Full Bio

Leave a Comment