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:
- Create a new user using the command:
sudo adduser [name_of_user]
- Add new user to sudo group:
sudo usermod -aG sudo [name_of_user]
- Confirm User belongs to the Sudo group:
groups [name_of_user]
- 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:
- First launch a Ubuntu Terminal by pressing CTRL+ALT+T.
- Insert the following command to create a user:
adduser simpsons
EXPLANATION- adduser: Adds a new user.
- simpsons: Creates a new user named simpsons.
- 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.
- 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.
- Finally, you can check whether the user has been created or not by running the following command:
getent passwd | grep simpsons
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
- usermod: Modifies an existing user account.
- -aG: Adds a user to the specific group.
- How to Create a Jenkins User on Ubuntu? [2 Methods]
- How to Create MySQL User in Ubuntu? [2 Cases]
- Create User Without Home Directory in Ubuntu in Just 3 Steps
- How to Create a User in Docker Container Without Docker File?
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.
4. Check Sudo Access of the New User
To check whether the user has sudo access, follow the below steps:
- Type the following command:
su - simpsons
Here
su -
command supersedes the current user sowad and switches it to simpsons as a root. - Then, execute the
sudo whoami
command. - 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.
- How to Create an FTP User in Ubuntu? [Step-by-Step]
- Create a New SFTP User in Ubuntu with a New SSH Key
- How to Create Group and Add User in Ubuntu? [2 Cases]
- Create FTP User for Specific Directory in Ubuntu [4 Steps]
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.
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.
- How to Create Multiple Users in Linux? [2 Methods]
- Create a User in Ubuntu as Read-Only Access to Log Folder
- How to Create User Account in Ubuntu with Public Key
- Create A User in Ubuntu that Runs a Script and Logs Out [4 Steps]
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.
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.
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
- How to Create User and Add to Sudo in Ubuntu? [2 Methods]
- 2 Ways to Create a User With Access to a Drive in Ubuntu
- How to Create a New User in Ubuntu by GUI? [Step-by-Step]
- 2 Ways to Create User Account in Ubuntu Using Terminal
- How to Create Home Directory for Existing User in Ubuntu
- Create User with UID and GID in Ubuntu? [3 Scenarios]
- How to Create a Root User in Ubuntu [Step-by-Step]
FUNDAMENTALS A Complete Guide for Beginners