Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1
forget  to  exit    root,   you could   cause   severe  damage  to  the system. It  is
usually better to choose one method or the other and use it consistently, and
the Ubuntu community consistently uses and recommends using sudo for
each command, even if it gets tedious, because it is a good reminder to
think about what you are doing.

After it is configured, using sudo is simple. An authorized user merely
precedes a super user authority-needed command with sudo, like this:


Click here to view code image
matthew@seymour:~$ sudo command


When the command is entered, sudo checks the /etc/sudoers file to see
whether the user is authorized to wield super user privileges; if so, sudo use
is authorized for a specific length of time. The user is then prompted for her
password (to preserve accountability and provide some measure of security),
and then the command is run as if root had issued it. During the time allotted,
which is 15 minutes by default in Ubuntu, sudo can be used again once or
multiple times without a password. If an unauthorized user attempts to
execute a sudo command, a record of the unauthorized attempt is kept in the
system log, and a mail message is sent to the super user.


Three man pages are associated with sudo: sudo, sudoers, and visudo.
The first covers the command itself, the second the format of the
/etc/sudoers file, and the third the use of the special editor for
/etc/sudoers. You should use the special editing command because it
checks the file for parse errors and locks the file to prevent others from
editing it at the same time. The visudo command uses the vi editor, so you
might need a quick review of the vi editing commands found in Chapter 12,
“Command-Line Master Class, Part 2,” in the section “Working with vi.”
You begin the editing by executing the visudo command with this:


Click here to view code image
matthew@seymour:~$ sudo visudo


The default /etc/sudoers file looks like this:


Click here to view code image


/etc/sudoers



This file MUST be edited with the 'sudo' command as root.



See the man page for details on how to write a sudoers file.



Defaults env_reset

Free download pdf