How to do it...

Let's start our activity as follows:

  1. Run the command in a new terminal, not as root, and without any previous sudo authorization:
$ shutdown -h 10$ shutdown -c
  1. Now, execute the $ sudo visudo command and edit the script to include the following lines:
$ sudo visudo[sudo] password for rbrash: #Defaults env_resetDefaults mail_badpassDefaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"# Host alias specification# User alias specification# Cmnd alias specificationCmnd_Alias READ_CMDS = /sbin/halt, /sbin/shutdown# User privilege specificationroot ALL=(ALL:ALL) ALLbob ALL=(ALL:ALL) NOPASSWD: READ_CMDS# Members of the admin group may gain root privileges%admin ALL=(ALL) ALL# Allow members ...

Get Bash Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.