Red Hat Certified System Administrator RHCSA · Free Practice Question Hard
Question 28
Develop a script suitable for Red Hat Enterprise Linux 9 (RHEL 9) that accomplishes the following tasks:
Creates a new user account named 'new_user'.
Assigns '/home/new_user' as the home directory for this account.
Sets '/bin/bash' as the default shell for 'new_user'.
Grants 'new_user' sudo privileges. Ensure your script adheres to the best practices for user management in RHEL 9.
Show model answer
- #!/bin/bash
- # Create a new user with a home directory and bash shell
- sudo useradd -m -d /home/new_user -s /bin/bash new_user
- # Grant sudo privileges to the new user
- echo 'new_user ALL=(ALL) NOPASSWD:ALL' | sudo tee /etc/sudoers.d/new_user
- # Ensuring permissions are secure
- sudo chmod 0440 /etc/sudoers.d/new_user
This script uses useradd to create a new user 'new_user' with a specified home directory and shell. It then grants sudo privileges by adding a new file in '/etc/sudoers.d/' for 'new_user', following RHEL 9's best practices for user management and sudo configuration.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
