Red Hat Certified System Administrator RHCSA · Free Practice Question Medium
Question 4
On ServerA, create a new user named "Samir" and grant him the ability to execute commands with root privileges using sudo. Ensure clarity, conciseness, and accuracy, and consider alternative approaches.
-
A
Pass
-
B
Fail
Reveal correct answer
Correct answer: A
Explanation
Step-by-Step Solution
Step 1: Create the User Account
Command:
- $ sudo useradd Samir
Explanation: Creates a new user account named
Samir.
Step 2: Set the User's Password
Command:
- $ sudo passwd Samir
Explanation: This command assigns a password to
Samir, enabling him to log in.
Step 3: Grant sudo Privileges to Samir
Choose one of the following methods:
Method A: Modify the
sudoersFile (For Granular Control)Open the
sudoersFile Usingvisudo:- $ sudo visudo
Explanation:
visudoopens thesudoersfile in a safe environment, preventing syntax errors from locking you out.
Add Sudo Permissions for Samir:
Add this line below the section “Allow root to run any commands anywhere”:
- Samir ALL=(ALL) ALL
Explanation:
Samir: Specifies the user to grant permissions to.ALL=(ALL): Allows Samir to run commands as any user or group.ALL: Permits Samir to execute all commands.
Save and Exit: Press
Esc, type:wq, and hitEnter.
Method B: Add Samir to the
wheelGroup (Simpler, if Applicable)Add Samir to the
wheelGroup:- $ sudo usermod -aG wheel Samir
Explanation: The
wheelgroup typically has sudo privileges configured in/etc/sudoers, simplifying management for users who need fullsudoaccess.
Verify
wheelGroup Permissions insudoers:Ensure that the following line exists in
/etc/sudoersto enablesudoforwheelgroup members:- %wheel ALL=(ALL) ALL
Step 4: Verify Sudo Access
Command:
- $ sudo -l -U Samir
Explanation: This lists the commands
Samircan run withsudo, verifying that privileges are set up correctly.
Key Points and Best Practices
Understanding
sudoPrivileges:Authentication:
Samirwill authenticate with his own password, not the root password, for security and accountability.Logging: Commands executed with
sudoare logged in/var/log/secure, which helps in tracking privileged actions.Password Timeout: By default,
sudosessions last for 5 minutes of inactivity before requiring re-authentication.
Alternative Options:
Limiting Privileges: For limited
sudoaccess, grantSamirpermission only for specific commands. For example:- echo "Samir ALL=(ALL) NOPASSWD:/usr/bin/systemctl" | sudo tee /etc/sudoers.d/Samir
Explanation: This allows
Samirto runsystemctlcommands without a password prompt, while restricting access to other commands.
Security Considerations: Carefully assess the need for
sudoprivileges, especially if full access is unnecessary, as excessive privileges can pose security risks.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
