Take 2: sudo
I – Adding a user to the sudo group
- Start becoming superuser with
su
. Enter your root password. - Now, install sudo with
apt-get install sudo
. - Debian 10: add the user account to the group sudo with
/sbin/adduser username sudo
.
Where username is your user account. - Now, log out and then log in with the same user.
- Open a terminal and run
sudo echo 'Hello, world!'
,
enter your user password and that's it!
II – Adding an existing user to the sudoers file
The sudoers file is located at /etc/sudoers.
However, you should never modify the sudoers file with a text editor. Saving a bad sudoers may leave you with the impossibility of getting sudo rights ever again.
Instead, use visudo, a tool designed to make sure you don’t do any mistakes.
$ sudo visudo
This is what you should see.
At the end of the file, add a new line for the user.
john ALL=(ALL:ALL) ALL
By default, the account password will be asked every five minutes to perform sudo operations. However, if you want to remove this password verification, you can set the NOPASSWD
option.
john ALL=(ALL:ALL) NOPASSWD:ALL
If you want the password verification to be skipped for longer periods of time, you can overwrite the timestamp_timeout (in minutes) parameter in your sudoers file.
# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults mail_badpass
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
Defaults timestamp_timeout=30