Publish: 2023-05-06 | Modify: 2023-05-06
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.

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.

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
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
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.
I come from China and I am a freelancer. I specialize in Linux operations, PHP, Golang, and front-end development. I have developed open-source projects such as Zdir, ImgURL, CCAA, and OneNav.