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.