Sudoers Explained: Granting Privileged Access in RHCSA Exam Style Practice

Published On: 11 July 2025

Objective

In Linux system administration, few tools command as much respect and caution as sudo. This small but mighty utility allows regular users to perform tasks typically reserved for the root user. And if you are preparing for the Red Hat Certified System Administrator (RHCSA) exam, understanding how to configure and secure privileged access through the sudoers file is a vital skill you cannot afford to ignore. The objective of this blog is to explain the concept, structure and secure configuration of the sudoers file in a way that aligns with RHCSA exam requirements. It aims to help readers understand how to grant and manage privileged access in RHEL-based systems using best practices, real-world scenarios, and exam-style tasks ensuring both technical proficiency and exam readiness. In this guide, we will break down the essentials of sudo, explain how the sudoers file works, and walk through RHCSA-style scenarios where you will be expected to configure access correctly and securely. Whether you are a beginner or brushing up for the exam, this is your one-stop guide to mastering sudo the RHCSA way. 

Why Sudo Matters in Linux Administration

By default, only the root user can perform administrative tasks on a Linux system like adding users, installing packages, or restarting services. But giving every administrator the root password is both risky and impractical. Enter sudo. The sudo command allows a permitted user to execute a command as the superuser (or another user), as specified in the sudoers configuration file. It strikes the perfect balance between delegating administrative control and maintaining system security. 

What is the Sudoers File?

The heart of the sudo mechanism is the /etc/sudoers file. This file defines:

  • Who can run sudo

  • What commands they can run

  • As which users they can run them

  • From which terminals or hosts

Editing this file manually can be dangerous; a single syntax error might lock you out of administrative access. That is why it is recommended to use:


visudo   # Safely open the sudoers file with syntax checking

The visudo utility locks the file and performs a syntax check before saving, ensuring you do not corrupt the system. 

Basic Structure of Sudoers File

The "Basic Structure of Sudoers File" section explains the format of entries in the /etc/sudoers file, which controls who can use sudo, on what machines, as which users and for which commands.

Here’s a simplified look at what a typical /etc/sudoers file might contain:


root ALL=(ALL)   ALL     # root can run all commands on all hosts as any user
%wheel  ALL=(ALL)   ALL     # users in the wheel group can do the same

This section teaches RHCSA candidates how to read and interpret default sudo permissions, a key step before adding or modifying entries securely.

Similarly, %wheel allows any member of the wheel group to have the same full sudo privileges as root. 

Adding a User to the Sudoers File

There are two RHCSA-friendly ways to give a user sudo privileges:

Method 1: Add User to Wheel Group

This method is the safest and most RHCSA-aligned way to grant a user administrative privileges. The wheel group is a special user group defined in the /etc/sudoers file. By adding a user to this group, they inherit sudo rights automatically because of the %wheel ALL=(ALL) ALL rule. This approach avoids directly editing the sudoers file for each user and follows the principle of centralized privilege management.


usermod -aG wheel john    # Add user 'john' to the wheel group for sudo access

This command appends user john to the wheel group. Since the %wheel rule already exists in the sudoers file, john automatically inherits sudo rights.

Exam Tip: RHCSA often expects you to modify group memberships using usermod or gpasswd. Make sure you are fluent with both.

Method 2: Use visudo to Grant Specific Privileges

This method allows fine-tuned control over what commands a user can run with sudo. It involves manually adding user-specific rules to the /etc/sudoers file or a file inside /etc/sudoers.d/ using visudo.

Open the sudoers file:


visudo # Open the sudoers file safely

Add a custom rule:


john ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart httpd # Allow 'john' to restart Apache without password

This rule allows John to restart Apache without entering a password. Very useful in production but be cautious: overly broad permissions can be dangerous. 

Using Sudo in Action

Here’s how john would restart Apache as a non-root user:


sudo systemctl restart httpd # Execute Apache restart as sudo

If the NOPASSWD: tag was not set, john would be prompted for his own password. 

RHCSA Exam-Style Scenarios

Let’s walk through three examples similar to what you might encounter in the RHCSA exam.

Scenario 1: Add a User with Full Sudo Rights

Task: Create a user adminuser and give them full administrative privileges.

Steps:


useradd adminuser       # Create a new user
passwd adminuser        # Set the user's password
usermod -aG wheel adminuser # Add user to the wheel group

Done. Because the %wheel group already has sudo rights, adminuser is now a mini-root.

Explanation:
This is the most straightforward and RHCSA-recommended method. The %wheel ALL=(ALL) ALL rule already exists in /etc/sudoers, meaning any user added to the wheel group gains full sudo privileges. This task tests your knowledge of:

  • User creation

  • Password assignment

  • Group-based privilege escalation using usermod

RHCSA Skill Tested:
Basic user and group management, understanding of default sudo group configurations. 

Scenario 2: Allow a User to Restart Only the Apache Service

Task: Create a user webadmin and allow only Apache restarts via sudo.

Steps:


useradd webadmin        # Create the user
passwd webadmin         # Set the user's password
visudo                  # Safely open the sudoers File

Then add this line to sudoers:


webadmin ALL=(ALL) NOPASSWD: /bin/systemctl restart httpd # Limit sudo to restarting Apache only

This ensures webadmin can only restart Apache, nothing else.

Explanation:
This scenario demonstrates granular privilege assignment. Rather than giving full sudo access, you allow the user to run just one specific command: restarting Apache. The use of NOPASSWD: lets the command run without prompting for the user's password.

This mimics real-world configurations where web admins may need limited control over services without exposing the full system.

RHCSA Skill Tested:

  • Using visudo safely

  • Writing specific sudoers rules

  • Limiting sudo access to a single command 

Scenario 3: Audit Sudo Usage

Task: View all sudo usage on the system.

Command:


grep sudo /var/log/secure    # Check sudo activity in secure log (RHEL/CentOS)

Or, on newer systems with journalctl:


journalctl | grep sudo       # Use journalctl to filter sudo usage

This is vital for auditing and can help you verify the exam task outcomes.

Explanation:
This task is about system auditing and troubleshooting. In RHCSA exams or real systems, it is important to verify which commands were run using sudo and by whom. This helps in:

  • Investigating misuse or unauthorized access

  • Confirming whether sudo privileges were used as intended

  • Tracking privilege escalation attempts

RHCSA Skill Tested:

  • Understanding Linux logging systems

  • Using journalctl effectively (critical for RHEL 8/9)

  • Sudo-related security auditing 

Summary Table

Scenario

Key Concept

Command Focus

RHCSA Skill Area

1. Full Sudo via Group

Group-based privilege

usermod -aG wheel

User/Group management

2. Limited Sudo Access

Command-specific sudo rules

visudo + /bin/systemctl

Privilege delegation

3. Auditing Sudo

Log and audit sudo use

journalctl, grep

System security & auditing

Common Mistakes to Avoid

  • Editing /etc/sudoers directly with nano or vim: Avoid editing the sudoers file directly with standard editors like nano or vim, as a single syntax error can break sudo access system-wide. Always use visudo, which locks the file and checks for errors before saving.
  • Giving full sudo to users unnecessarily: Granting unrestricted sudo access (ALL=(ALL) ALL) to users who only need limited commands poses a security risk. Always follow the principle of least privilege to minimize potential damage from misuse or compromise.
  • Misspelling commands or paths in custom rules: Even a minor typo in command paths (like /usr/bin/systemctl vs /bin/systemctl) can render your sudo rule ineffective. Validate exact command paths using which <command> before adding them to the sudoers file.
  • Forgetting NOPASSWD: when the exam scenario demands password-less execution: If the exam task specifies that a user should execute a command without being prompted for a password, omitting the NOPASSWD: directive will cause the configuration to fail. Pay close attention to the wording in exam instructions. 

Bonus Tip: Using Included Directories

Instead of crowding the main sudoers file, you can create custom files inside:


/etc/sudoers.d/ # Directory for additional sudo rules

Example:


echo "devuser ALL=(ALL) NOPASSWD: /usr/bin/dnf install" > /etc/sudoers.d/devuser    # Add custom sudo rule

This modular approach is cleaner, easier to maintain and favored in enterprise setups. It also reduces the risk of corrupting the main sudoers file. 

Best Practices for Managing Sudo Access

  • Use groups (like wheel) to manage privilege escalation at scale.

  • Use command-specific sudo rules to control administrative access.

  • Regularly audit sudoers entries and remove unnecessary privileges.

  • Never disable password prompts for sensitive actions unless justified.

  • Always test new sudo rules on a non-critical user before deploying system-wide. 

Conclusion

Understanding and configuring the sudoers file is more than just an exam task; it is foundational to safe, efficient Linux administration. In the RHCSA exam, tasks related to user privilege escalation are common and mistakes can lead to lost points or failed scenarios. If you want hands-on labs, mock questions and one-on-one guidance for mastering topics like sudo, visudo, and much more, check out RHCSA.GURU. Whether you are just starting your RHCSA journey or aiming to tighten your command-line skills, RHCSA.GURU offers a structured path, expert advice, and practical content to help you pass the exam and thrive in the real world.