In this lesson, we explore how privilege escalation works in Linux and why it is critical from a security perspective. Previously, we disabled root user login via SSH because using the root account for routine tasks poses significant security risks. However, performing administrative tasks—such as installing software or conducting system maintenance—still requires elevated privileges. One of the most effective methods to execute commands with root privileges is through the sudo command. Using sudo enables trusted users to run administrative commands by providing their own password, which not only strengthens security but also creates an audit trail of actions performed.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
For enhanced security, always use sudo rather than logging in directly as root.
Using Sudo Versus Direct Commands
If you attempt to install a package without sudo privileges, you will encounter a permission error:Understanding the /etc/sudoers File
The default configuration for sudo is maintained in the/etc/sudoers file. This file governs policies for executing commands with elevated privileges and can only be modified by users who have been explicitly granted access. Only users listed in the /etc/sudoers file can use sudo, thereby preventing unauthorized root logins.
Below is an excerpt from the /etc/sudoers file that demonstrates a granular assignment of privileges:
- User or Group: The first field specifies the user or group (groups are prefixed with
%) that receives the privileges. - Host Specification: The second field, typically set to
ALL, indicates that the privileges apply to all hosts (commonly confined to the localhost). - Run-as Specification: The third field, enclosed in parentheses, indicates the user(s) as whom the commands will be executed. “ALL” means that commands can be run as any user.
- Command Specification: The fourth field specifies the allowed commands. Using “ALL” permits any command, though you can restrict users to specific commands, as demonstrated in the entry for Sarah.
Avoid modifying the
/etc/sudoers file improperly—always use the visudo command to safely edit this file.