How to Create a Sudo User on Debian 12

When setting up a fresh Debian 12 server, the root user is typically the only account with administrative privileges. Logging in as the root user for daily tasks is a major security risk. The best practice is to create a standard user and add them to the sudo group, allowing them to temporarily elevate their privileges only when necessary. Here is how to create a sudo user on Debian 12 using the usermod command.

Adding a User to the Sudo Group

To grant an existing user sudo privileges, you must be logged in as root. Follow these steps:

  1. Open your terminal or connect to your Debian 12 server via SSH.
  2. Switch to the root user by typing the following command and entering your root password:
su -
  1. Once you have root access, use the usermod command to append the user to the sudo group. Replace username with the actual name of your user:
usermod -aG sudo username

It is critical that you include the -a (append) flag. If you use -G without -a, the user will be completely removed from all other groups they belong to, which can break system access.

Verifying Sudo Privileges

After running the command, you should verify that the user was successfully added to the group.

  1. Check the user’s group memberships by running:
groups username
  1. You should see sudo listed in the output string.

Important: Group permission changes do not take effect immediately in active sessions. The user must completely log out of the server and log back in (or open a new SSH connection) for the sudo privileges to activate. Simply opening a new terminal tab within the same desktop session will not refresh the permissions.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.

Receive our best articles and tips delivered straight to your inbox.