Introduction
Before we begin talking about how to create a Sudo User on Ubuntu 22.04, let’s briefly understand - What is a Sudo User?
The sudo
command helps users to run programs with the security privileges of another user, which is a root user by default. By utilizing the sudo command, regular users can temporarily gain access to perform tasks that would typically require administrative permissions.
This secure mechanism enhances system security by restricting root access, reducing the risk of unauthorized or accidental system modifications. Sudo user is a vital tool for granting users elevated privileges while maintaining control over system access and safeguarding against potential security threats.
In this tutorial, you will create a Sudo User on Ubuntu 22.04. We will also answer some FAQs related to a Sudo user.
Step 1 - Create a Sudo User
1) You will need to create a new user account. Then, give it sudo access.
Login to your system as the root user.
ssh root@server_ip_address
2) After that, create a new user account using the adduser
command. Also, remember replacing username
with the username you want to create.
adduser username
3) You will get a prompt to set as well as confirm the new user password. Make sure, that the password for the new account is strong:
Output
Adding user `username' ...
Adding new group `username' (1000) ...
Adding new user `username' (1000) with group `username' ...
Creating home directory `/home/username' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
4) After setting a password, the command will create a home directory for the user. Next, it will copy several configuration files in the home directory. It will again prompt you to set new users’ information. In case you want to leave all of this information blank. For that, press ENTER
to accept the defaults.
Output
Changing the user information for username
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n]
5) Now, you will add a new user to the sudo
group. By default, on Ubuntu systems, members of group sudo, have sudo access. You will now add the user you made to sudo group using the usermod
command:
usermod -aG sudo username
Step 2 - Test the Sudo-access
1) Now you will switch to the newly made user.
su - username
2) Now, you will use sudo
to run the whoami
command.
sudo whoami
3) You will now ensure if the user has sudo access. The output of whoami
command will be root:
Output
root
Step 3 - Using the Sudo
1) To use sudo, you will need to prefix the command with sudo
and then space.
sudo ls -l /root
2) If you are using sudo for the first time in a session, you will get a prompt to enter the password.
Output
[sudo] password for username:
FAQs to Create a Sudo User on the Ubuntu 22.04
How to list the Sudo-privileges?
You will first run the sudo -l . This will list the sudo-privileges you have as it will not stuck on the password input.
Is the Sudo a root?
The Sudo runs a single command with root privileges. This is a key difference between su
as well as sudo
. The Su switches the user to the root user account. Moreover, needs the root account's password. Whereas, the Sudo runs a single command with root privileges. So, it will not switch to the root user. Even do not need a separate root user password.
What command can be used to add a new user on Ubuntu?
The command adduser
allows you to add a new user on Ubuntu. For example, sudo adduser newuser
creates a new user called "newuser".
How can I add an existing user to the sudo group?
You can use the usermod
command to add an existing user to the sudo group. The command would look like: sudo usermod -aG sudo existinguser
.
Can I create a sudo user during Ubuntu installation?
Yes, during Ubuntu installation, you can create a sudo user by specifying the username and granting administrative privileges.
Can I change the sudo user's password?
Yes, you can change the sudo user's password using the passwd
command. Simply execute sudo passwd username
and follow the prompts.
How can I check if a user has sudo access?
You can check if a user has sudo access by running the groups
command followed by the username. If sudo
is included in the output, the user has sudo access.
Conclusion
We hope this detailed guide helped you understand how to create a Sudo user on Ubuntu 22.04.
If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.