0%

0/1 Lessons

Introduction to Linux Server Operating Systems

• 30min

0 / 3 lessons complete

Linux Server Installation and Lab Setup

• 23min

0 / 6 lessons complete

Working with the Linux Command Line Interface

• 1hr 30min

0 / 12 lessons complete

User and Group Management

• 44min

0 / 7 lessons complete

Linux Storage

• 30min

0 / 6 lessons complete

Linux Administration Basics

• 53min

0 / 8 lessons complete

Linux Networking

• 47min

0 / 8 lessons complete

Course Conclusion

• 5min

0 / 1 lessons complete

The sudoers File

Instructions

Q&A (0)

Notes (0)

Resources (0)

Saving Progress...

Resources

There are no resources for this lesson.

Notes can be saved and accessed anywhere in the course. They also double as bookmarks so you can quickly review important lesson material.

Create note

In this lesson, we will explore how to delegate administrative privileges using the sudo command and how to manage sudo permissions through the /etc/sudoers file. This will enable us to run commands as another user, typically the superuser, which is essential for performing system administrative tasks.

Let's take a look at our john_doe user if he tries to run the sudo command:

john_doe@ip-10-0-7-219:/home/iacadmin$ sudo whoami
# [sudo] password for john_doe: 
# john_doe is not in the sudoers file.  This incident will be reported.

We can see that the user was unable to run the sudo command because they are not in the sudoers file. In this lesson, you will learn how to fix this issue.

Understanding the Sudoers File

The /etc/sudoers file is a crucial configuration file that specifies which users and groups can run what commands on which hosts, and as which users. It's a central part of the sudo system and requires careful editing to ensure system security and functionality.

Syntax of the Sudoers File

The syntax for entries in the /etc/sudoers file is as follows:

user host=(run_as_user:run_as_group) commands

Here's a breakdown of the syntax user host=(run_as_user:run_as_group) commands:

  1. user:
    • This is the username of the individual who is being granted permissions. This could also be a %group if you are specifying a user group instead of an individual user.
  2. host:
    • This specifies the hostname or hostnames on which this rule applies. This allows for host-specific rules in environments where the /etc/sudoers file is shared across multiple machines.
  3. (run_as_user:run_as_group):
    • This part specifies as which user and/or group the commands can be executed.
    • run_as_user: The username that the user is allowed to switch to.
    • run_as_group: The group name that the user is allowed to switch to.
    • If either is set to ALL, it means the user can run commands as any user or group respectively.
  4. commands:
    • This is the list of commands that the user is allowed to run. This could be a single command, a list of commands separated by commas, or the keyword ALL to allow all commands.

Editing the Sudoers File

visudo (Edit the Sudoers File) To edit the sudoers file, it's recommended to use the visudo command, which opens the file in a safe fashion and checks for syntax errors before saving:

sudo visudo

Adding a User to the Sudoers File

To grant a user sudo privileges, you add them to the sudoers file with the appropriate permissions. For example, to allow john_doe to run all commands as any user by adding the following to the bottom of the /etc/sudoers file:

john_doe ALL=(ALL:ALL) ALL

Creating an Alias

You can create a command alias to group commonly used commands together. For instance, to group a few commands under the alias MY_CMDS:

# Cmnd alias specification
Cmnd_Alias MY_CMDS = /bin/whoami, /bin/ls

Granting Limited Sudo Access

You can also grant a user access to only specific commands. For instance, to allow john_doe to run only the commands in our group:

# In the sudoers file:
john_doe ALL=(ALL:ALL) MY_CMDS

Validating Sudo Access

sudo -l (List User Sudo Permissions) After editing the sudoers file, you can check a user's sudo permissions with the sudo -l command:

sudo -l -U john_doe

Testing Limited Sudo Access

From your root user, su to john_doe:

sudo su john_doe

Next I will CD to my iacadmin user which is used in our cloud labs and try to LS that directory. It will fail but we can then run sudo ls, which will succeed:

Server Academy Members Only

Sorry, this lesson is only available to Server Academy Full Access members. Become a Full-Access Member now and you’ll get instant access to all of our courses.

0 0 votes
Lesson Rating
Subscribe
Notify of
profile avatar
0 Comments
Inline Feedbacks
View all comments