How To Add A User To The Sudoers File in Linux
How To Add A User To The Sudoers File in Linux
Learn more.
How-To Geek
Linux
Key Takeaway
If you're being told a user "is not in the sudoers file," you can
add a sudo user with the usermod command. To control
what a user can do with sudo, edit the sudoers file with
visudo.
Table of Contents
Nominated users
RELATED
can use sudo to
8 Ways to Tweak and
temporarily gain
Configure Sudo on
administrative Ubuntu
powers, perform
the action that is required, and then return to their normal,
unprivileged state. This is safer because you consciously
invoke your higher powers when you need them, and while
you’re focused on doing whatever it is that requires them.
That seems plain enough. Our user mary can’t use sudo
because she isn’t “in the sudoers file.” So let’s see how we can
add her, making her a sudo user.
sudo visudo
Scroll down in the editor until you see the “User Privilege
Specification” section. Look for a comment that says
something similar to “Allow members of this group to execute
any command.”
We’re told that members of the sudo group can execute any
command. All we need to know in Mary’s case is the name of
that group. It isn’t always sudo ; it might be wheel or something
else. Now that we know the name of the group, we can close
the editor and add Mary to that group.
The next time Mary logs in, she’ll have access to sudo. We’ve
logged her in and we’re trying to edit the file system table file,
“/etc/fstab.” This is a file that is out of bounds to everyone
but root.
Close the editor and don’t save any changes you may have
made.
sudo visudo
Scroll down in the editor until you see the “User Privilege
Specification” section. Look for a comment that says
something similar to “Allow the members of this group to
execute any command.” It’s the same point in the file where we
found the name of the group we needed to add Mary to.
Let’s log Tom in and see if we get the expected behavior. We’ll
try to edit the “/etc/fstab” file.
If all your users can use sudo, you’ll have chaos on your hands.
But it is worth promoting other users to the sudoers list so
they can share your administrative burden. Just make sure
they’re worthy, and keep an eye on them.
Even if you’re the only user on your computer, it’s worth
considering creating another user account and adding it as
a sudo user. That way, if you ever find yourself locked out of
your main account, you have another account you can log in
with to try to remedy the situation.
DAVE MCKAY
Dave McKay first used computers when
punched paper tape was in vogue, and he has
been programming ever since. After over 30
years in the IT industry, he is now a full-time
technology journalist. During his career, he has worked as a
freelance programmer, manager of an international software
development team, an IT services project manager, and, most
recently, as a Data Protection Officer. His writing has been
published by howtogeek.com, cloudsavvyit.com,
itenterpriser.com, and opensource.com. Dave is a Linux
evangelist and open source advocate. READ FULL BIO »
How-To Geek is where you turn when you want experts to explain technology. Since we
launched in 2006, our articles have been read more than 1 billion times. Want to know
more?