Red Hat Certified System Administrator RHCSA · Free Practice Question Medium
Question 36
Develop a script for Red Hat Enterprise Linux 9 that accomplishes the following tasks:
Create a new user called 'new_user', ensuring they have a home directory located at
/home/new_userand a default shell set to/bin/bash.Grant 'new_user' sudo privileges.
Verify if a symbolic link named 'symlink' to the file
/etc/passwdalready exists. If it does not, create this symbolic link.
Show model answer
- #!/bin/bash
- # Add new user with specified home directory and shell
- useradd -m -d /home/new_user -s /bin/bash new_user
- # Grant sudo privileges
- echo "new_user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
- # Check and create symbolic link if not exists
- if [ ! -L /path/to/symlink ]; then
- ln -s /etc/passwd /path/to/symlink
- fi
This script uses useradd to create a new user, edits the /etc/sudoers file for sudo privileges, and creates a symbolic link if it doesn't already exist.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
You must be logged in to post a comment.
