Add new sudo user
To add a new sudo user on a Linux system, you can follow these steps:
Method 1: Using the usermod
command
- Open a terminal as the root user or use
sudo
to gain root privileges. - Run the following command to add a new user:
usermod -aG sudo <new_username>
Replace
<new_username>
with the desired username for the new user.
Method 2: Using the adduser
command
-
Open a terminal as the root user or use
sudo
to gain root privileges. -
Run the following command to add a new user:
adduser <new_username>
Replace
<new_username>
with the desired username for the new user. -
Once the user is created, run the following command to add the user to the sudo group:
usermod -aG sudo <new_username>
Method 3: Using the
visudo
command -
Open a terminal as the root user or use
sudo
to gain root privileges. -
Run the following command to edit the sudoers file:
visudo
-
Add the following line at the end of the file:
<new_username> ALL=(ALL) NOPASSWD:ALL
Replace
<new_username>
with the desired username for the new user. -
Save and exit the editor.
In all cases, the new user will not have a password set by default. You can set a password for the new user using the passwd
command:
passwd <new_username>
Replace <new_username>
with the desired username for the new user.
Note: The usermod
and adduser
commands can be used to add a new user to the system, but they do not automatically add the user to the sudo group. The visudo
command is used to edit the sudoers file and add the user to the sudo group.