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
sucommand and then entering the root password.
- Use the
addusercommand to add a new user. Replace
usernamewith the desired username:
- Add the new user to the
sudogroup by running the following command:
usermod -aG sudo username
- Verify that the user has been added to the
sudogroup by running the
- Log out of the root user account by running the
- Log in as the new user and verify that you can use
sudoby running a command that requires superuser privileges, such as
sudo 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
sudogroup are allowed to use the
sudocommand to run any command as the root user. If you want to restrict the user’s
sudoprivileges, you can do so by editing the
/etc/sudoersfile. This file specifies which users are allowed to use
sudoand which commands they are allowed to run.
- To edit the
/etc/sudoersfile, you can use the
visudocommand. 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
visudocommand to add specific
sudoprivileges for a user. For example, to allow the user
usernameto run the
aptcommand without a password, you can add the following line to the
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/sudoersfile, as incorrect changes can cause problems with your system. If you are not familiar with the
/etc/sudoersfile, it is generally best to ask your system administrator for assistance.