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

  1. Open a terminal as the root user or use sudo to gain root privileges.
  2. 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

  1. Open a terminal as the root user or use sudo to gain root privileges.

  2. Run the following command to add a new user:

    adduser <new_username>

    Replace <new_username> with the desired username for the new user.

  3. 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

  4. Open a terminal as the root user or use sudo to gain root privileges.

  5. Run the following command to edit the sudoers file:

    visudo
  6. 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.

  7. 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.