Tuesday, December 29, 2020

Take 2: sudo

 Take 2: sudo

I – Adding a user to the sudo group

  1. Start becoming superuser with su. Enter your root password.
  2. Now, install sudo with
     apt-get install sudo.
  3. Debian 10: add the user account to the group sudo with 
    /sbin/adduser username sudo.
     Where username is your user account.
  4. Now, log out and then log in with the same user.
  5. 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.

This file contains a set of rules that are applied to determine who has sudo rights on a system, which commands they can execute with sudo privileges, and if they should be prompted a password or not. 

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.

The sudoers file on Debian 10 Buster

At the end of the file, add a new line for the user.

john       ALL=(ALL:ALL) ALL
Sudoers syntax on Debian 10

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


No comments:

Post a Comment