To add a new user as a sudoer in Ubuntu, follow these steps:
- Open a terminal and log in as the root user. You can do this by running the
su
command and then entering the root password. - Use the
adduser
command to add a new user. Replaceusername
with the desired username:
adduser username
- Add the new user to the
sudo
group by running the following command:
usermod -aG sudo username
- Verify that the user has been added to the
sudo
group by running thegroups
command:
groups username
- Log out of the root user account by running the
exit
command. - Log in as the new user and verify that you can use
sudo
by running a command that requires superuser privileges, such assudo apt update
.
Note that you must have root privileges to add a user to the sudo
group. If you do not have root privileges, you will need to ask your system administrator to add the user for you.
Here are a few additional details that may be helpful:
- By default, members of the
sudo
group are allowed to use thesudo
command to run any command as the root user. If you want to restrict the user’ssudo
privileges, you can do so by editing the/etc/sudoers
file. This file specifies which users are allowed to usesudo
and which commands they are allowed to run. - To edit the
/etc/sudoers
file, you can use thevisudo
command. This command opens the file in a text editor and checks the syntax of the file before saving any changes. - You can also use the
visudo
command to add specificsudo
privileges for a user. For example, to allow the userusername
to run theapt
command without a password, you can add the following line to the/etc/sudoers
file:
username ALL=(ALL) NOPASSWD: /usr/bin/apt
This will allow the user to run the apt
command using sudo
without being prompted for a password.
- Be careful when editing the
/etc/sudoers
file, as incorrect changes can cause problems with your system. If you are not familiar with the/etc/sudoers
file, it is generally best to ask your system administrator for assistance.