How to Add User to Sudoers in Debian

Table of Content
    Add a header to begin generating the table of contents
    How to add user to Sudoers file in Debian
      Add a header to begin generating the table of contents

      If you’re new to Debian and unable to update package lists or install software using sudo, then this article is for you. We’ll describe two simple methods to add a user to the sudoers file in Debian.

      What is Sudoers File?

      The sudoers file is a critical configuration file that defines which users or groups can execute commands with superuser (root) privileges using sudo. These privileges allow users to update package lists and install software on the system. Therefore, having sudo privileges is essential for smooth system administration. This file is located at /etc/sudoers.

      How to Add User to Sudoers in Debian

      Adding the user to sudoers is an essential part of setting up your Debian because without sudo privileges, installing and updating packages is impossible. However, it can be tricky for beginners, as it requires root privileges and modifying a critical file:

      User not present in Sudoers file in Debian

      Therefore, let’s learn two methods of adding users to the sudoers file in Debian.

      1. By Editing Sudoers File

      To add a user to sudoers by editing the sudoers file, ensure that you’re logged in as a user with sudo privileges. However, if that’s not the case, run the following command to switch to the superuser:

      $ su root

      Now that you’ve switched to the superuser and have sudo privileges, open the sudoers file using any editor:

      $ nano /etc/sudoers  
      switch to root user and open sudoers file using nano editor

      Thus, the sudoers file will open:

      Open Sudoers file in Debian

      Afterward, scroll down to the User Privilege Specification section and add the following line of code. However, make sure you replace username with the actual username in the file:

      username  ALL=(ALL:ALL) ALL
      Grant privileges to new user in sudeors file in Debian

      After modifying the file, press Ctrl+O to save and press Enter. Afterward, exit the editor by pressing Ctrl+X. Now, the new Debian user will be able to execute any command as any user or group. For instance, let’s execute the apt update command to verify:

      execute apt update command

      Finally, the user has been successfully added to the sudoers file. Now, you can easily run any command without worrying about sudo privileges.

      2. Via usermod Command

      Another method of adding a user to sudoers is via the usermod command, a popular Linux command used to modify an existing user’s account settings. Again, ensure you’ve logged in as a user with sudo privileges. However, if that’s not the case, run the following command to switch to the super user:

      $ su root

      Next, execute the following usermod command. Notably, replace the username with the actual username to add the user to the sudo group, granting the user sudo privileges:

      $ usermod -aG sudo username

      Afterward, to ensure that the user is added to sudoers, run the command given below:

      # sudo whoami

      If the output is root, it means the user has been successfully added to the sudoers file. Now, exit the superuser mode by using the command below:

      # exit
      usermod command

      Finally, the usermod command has successfully added the user to the sudoers file in Debian.

      Conclusion

      To keep all packages up to date or install software, the user requires sudo privileges. In this article, we’ve explained how you can add a user to the sudoers file in Debian. You can either open the sudoers file, located at /etc/sudoers, using any editor and add ALL permissions for the new user under the User Privilege Specification section, or you can simply execute the usermod command to directly add the user to the sudoers file.

      Latest Post

      Contents
        Add a header to begin generating the table of contents
        How to add user to Sudoers file in Debian
        Latest Post
        Do You Enjoy My Blog

        Supports from reader you like keeps this blog running. By a cup of coffee for me , its a affordable way to show your appreciation

        Previous Post
        ABOUT THE AUTHOR
        Maryam Nasir

        I'm currently pursuing my Bachelor's degree. Alongside my studies, I specialize in jotting down my knowledge about Linux by effectively and practically using my hobby of writing.

        Scroll to Top