Adding a new user with sudo privileges in Debian system

Publish: 2023-05-06 | Modify: 2023-05-06

Introduction

For security reasons, when setting up a new server, it is common practice to create a new user with sudo privileges and disable the root user. This article outlines and shares the steps to accomplish this on a Debian system.

Debian

Adding a New User

Simply execute the following command:

# Replace 'newuser' with your desired username
sudo adduser newuser

The adduser command is specific to Debian-based systems (including Ubuntu) and is not present in Redhat-based systems. This command will automatically create the user, user group, and home directory, and prompt for additional information such as the user's password and name.

Add User

Granting Sudo Privileges

Some Debian systems may not have the sudo command installed by default. You can install it by executing the following command (requires root user privileges):

apt-get install sudo

Once installed, execute the following command (requires root user privileges) to add the new user to the sudo group, granting them administrative privileges:

# Replace 'newuser' with the username from the previous step
usermod -aG sudo newuser

Testing

Switch to the newuser and test if sudo is functioning correctly:

# Switch to newuser
su - newuser

# Test sudo privileges, if no error is displayed, it is working correctly
sudo pwd

Conclusion

Creating a new user and granting sudo privileges on a Debian-based system is straightforward. With just a few commands, you can complete the process without the need to modify configuration files, making it more convenient compared to Redhat-based systems.


Comments