Sudoers
How to act as the root user
See the Users cheatsheet for creating a user and adding them to the sudo group.
View manpage
$ man sudoers
Run as superuser
Perform action as root
$ sudo COMMAND
Change to root user
This is not recommended, as you might forget you are superuser. Also you won’t have any alias like the interactive remove or copy which prevents overrides.
$ sudo su
Configs
Read the sudoers config file. Do not edit this directly.
$ view /etc/sudoers
Edit using:
$ sudo visudo
Note if you want to give a user sudoers ability, do not add them to the file. Rather add them to sudo group as per Users cheatsheet.
See also a directory for adding local content.
$ ls /etc/sudoers.d/
Do admin actions without entering password
Configure your system to avoid entering your password every time your run sudo.
Add this as a row to sudoers config under this section. Replace foo
with your target username so your user is affected.
foo ALL=(ALL) NOPASSWD:ALL
It might even work do to %foo
if that references a group.
Another source says to edit the admin
line instead - remember this will affect all users on your machine with admin access, not just yours.
%admin ALL=(ALL) NOPASSWD: ALL
Note also admin
and sudo
groups are different. Admin users “may gain root privileges” and sudo users can “execute any command”, according to notes in sudoers file.
Remember sudo password for a set time
The machine will not prompt you again for your password for a time. More secure than the above as you stay your own user and don’t have to enter your user’s password on every command, only once for multiple commands.
- Edit sudoers file.
- Set a default in seconds - here 5 minutes.
Defaults timestamp_timeout=300