2 Ways to add users to sudoers group in Debian 11

Set up sudoers users in Debian 11 using this tutorial: The “Sudoers” is a file in which the rights of the users are managed. For example, the system administrator (root) can assign another user root rights.

The additional user with sudo rights  can then:

  • Execute commands with root rights
  • View files that only users with root privileges can open (e.g. the / etc / shadow file)
  • In the same way, the system administrator can revoke the rights of the user by removing the user from the Sudoers file.

 

Debian 11 Linux: Add an existing user to the sudo group

#Ist method:

After installing Debian, the /etc/sudoers file must be edited first, otherwise commands with root rights cannot be executed. However, for that, you must first switch to the root user. The following command-line command adds an existing user to an existing group.

First Switch to root user

The below command allows you to switch to the root user. When it asks for the password enter the one you have set for your Debian 11 root user.

su -

Add an existing user to the Debian 11 sudo group

Now, I am assuming that you already have a user on your Debian system that you want to add to the sudo group for running commands under root rights. If yes, then follow the below command.

You may get an error while usermod that the command is not found, so

First, run this:

ln /usr/sbin/usermod /usr/bin

Now, use:

usermod -aG {Group} {Username}
  • sudo = Work with root rights
  • usermod = changes a user account
  • -aG = –append (adds the user to further groups), G = –groups (groups)

Example:

usermod -aG sudo rajm

Change the rajm in the above command with the system user that you want to add to the sudo group.

 

Furthermore, if you don’t have any other user apart from root or you want to add a new user then run:

adduser username

The above command will allow you to add a new user. Note: Replace username with the name that you want to give your new user.

 

#2nd way

If the above method didn’t work for you then directly edit the Sudoers file to add the user to it. For that use the below commands:

Switch to the root user, if you already have not.

su root

Edit Sudoers file on Debian 11

Now, edit the sudoers file using the given command.

nano /etc/sudoers

Add your User

Scroll down to the end of the file and add the following line.

username ALL=(ALL:ALL) ALL

Note: Replace the username with the user that you want to add to the sudo group in Debian 11 Bullseye.

For example, here our username is rajm, thus the above command will be like this:

rajm ALL=(ALL:ALL) ALL

add users to sudoers group in Debian 11

 

Save the file by pressing Ctrl + O and exit the file by using the Ctrl +X keys.

That’s it, now you can run your existing user with sudo rights on Debian 11 Bullseye or 10 Buster.

 

 

3 thoughts on “2 Ways to add users to sudoers group in Debian 11”

  1. Thank you so much for adding this help page for adding SUdoers

    The first method didn’t work because Bash said command “usermod” didn’t exist.
    But I’m familiar enough with Linux that I was able to go into the sudoers config and add my user name.

    Thank you thank you

    Reply
  2. Thank you!
    The second method (using nano) worked for me. I don’t know why the others don’t, but I have a functional system now. I’m not a Linux ninja, just someone trying to revive an old computer.

    Reply
  3. While using this tutorial, I found two things that you could change:

    1. Instead of using nano /etc/sudoers, you can just use the command “visudo” to do the same thing.
    2. To make things fit better, add the username ALL=(ALL:ALL) ALL part under the user privilege specification comment.

    This is a very nice tutorial still, thanks for making this!

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.