The terminal also prompts you to change the user information. Fill in the details or hit Enter to leave the fields blank.

STEP 3: Add user to the sudo group

Users with root privileges can add any account to the sudo group. On Debian and Ubuntu systems, everyone in this group automatically gets sudo access.

Run the following command to add a user to the sudo group:

usermod -aG sudo username

The command consists of the following parts:

usermod is the tool that modifies a user account.

-aG is the option that tells the command to add the user to a specific group. The -a option adds a user to the group without removing it from current groups. The -G option states the group where to add the user. In this case, these two options always go together.

sudo is the group we append to the above options. In this case, it is sudo, but it can be any other group.

username is the name of the user account you want to add to the sudo group.

To verify the new Debian sudo user was added to the group, run the command:

getent group sudo

The output lists all users in the group.

Verify Sudo Access in Debian

To make sure the new user has sudo privileges:

1. Switch to the user account you just created:

su - username

2. Run any command that requires superuser access. For example, sudo whoami should tell you that you are the root.

Using Sudo

To run a command with root access, type in sudo and enter the desired command.

For example, to view details for the root directory, run the ls tool as:

sudo ls -la /root

Enter the user’s password, and the terminal shows the contents of the root directory. You only need to enter the password once in the same session.

Conclusion

Now you know how to add a user with sudo privileges on Debian.

By following this guide, you can use the new account to run commands as a superuser. Remember to be careful when you execute sudo commands.