How To Add A User To Sudoers In Linux

Linux is known for its robust security features, one of which is the control of administrative privileges through the sudo command. The sudo command stands for “superuser do”, allowing authorized users to perform commands with administrative or root privileges. In this guide, we’ll walk you through the steps on how to add a user to sudoers in Linux.

Understanding the Sudoers File

The /etc/sudoers file is the system file that defines which users and groups have sudo privileges, and to what extent. It is advisable not to edit this file directly, but rather use the visudo command which opens an editor and does syntax checking on the file to prevent errors.

Adding a User to Sudoers

Let’s say we want to add a user named ‘tom’ to the sudoers. Follow the steps below:

  1. First, open your terminal and switch to the root user with the following command:

                su -
                
  2. Next, type the visudo command to edit the sudoers file:

                visudo
                
  3. You’ll see a file opened in the default text editor. Scroll down to find the section that looks like this:

                # User privilege specification
                root    ALL=(ALL:ALL) ALL
                
  4. Add the following line below the root entry, replacing ‘tom’ with the username you want to add:

                tom     ALL=(ALL:ALL) ALL
                
  5. Save and exit the file. In a VI editor, you can do this by typing :wq and press Enter.

Now, ‘tom’ is added to the list of sudoers and can execute commands with root privileges by using the sudo command. Remember that with great power comes great responsibility – only grant sudo privileges to trusted users!

Conclusion

That’s it! You’ve learned how to add a user to sudoers in Linux. Remember to use this power wisely and restrict it only to necessary users for maintaining the security of your system.