How to add your user on a Linux system to the /etc/sudoers file the proper way.

Posted: May 11, 2017. At: 11:30 PM. This was 10 months ago. Post ID: 7253
Page permalink.
WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters. These cookies expire two weeks after they are set.

Add a user to the sudoers file on Linux easily

If you need to add your user on a Linux system to the /etc/sudoers file, this is how to do it properly.

I am adding a new UNIX user to my system. This user will have sudo access.

[email protected]:~$ sudo adduser adler
Adding user `adler' ...
Adding new group `adler' (1002) ...
Adding new user `adler' (1002) with group `adler' ...
Creating home directory `/home/adler' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for adler
Enter the new value, or press ENTER for the default
	Full Name []: UNIX User.
	Room Number []: 101100001010
	Work Phone []: 
	Home Phone []: 
	Other []: 
Is the information correct? [Y/n] Y

Then we add the user adler to the sudoers file. Use the visudo command for this task.

[email protected]:~$ sudo visudo

Then add the adler user to the file and save.

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
 
# Host alias specification
 
# User alias specification
 
# Cmnd alias specification
 
# User privilege specification
root    ALL=(ALL:ALL) ALL
 
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
 
# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL
adler   ALL=(ALL:ALL) ALL
 
# See sudoers(5) for more information on "#include" directives:
 
#includedir /etc/sudoers.d

This will add the user adler to the /etc/sudoers file and then he will be able to execute commands after entering his password.

That is how easy this is. Remember to NEVER edit the /etc/sudoers file directly. Always use the visudo command.

There is more information on the /etc/sudoers file here: https://help.ubuntu.com/community/Sudoers.

No comments have been made. Use this form to start the conversation :)

Leave a Reply