Skip to Content

RHCSA Practice Exam

RHCSA Practice Exam A

Here are some tips to ensure your exam starts with a clean environment:

  • You do not need external servers or resources.
  • Do not register or connect to external repositories.
  • Install a new VM according to the instructions in each practice exam.
  • No sample solutions are provided for these practice exams. On the real exam, you need to be able to verify the solutions for yourself as well.
  • You should be able to complete each exam within two hours.

 

After applying these tips, you’re ready to get started. Good luck!

  • Install a RHEL 9 virtual machine that meets the following requirements
  • Create user student with password password, and user root with password password.
  • Configure your system to automatically mount the ISO of the installation disk on the directory /repo. Configure your system to remove this loop-mounted ISO as the only repository that is used for installation. Do not register your system with subscription-manager, and remove all references to external repositories that may already exist.
  • Reboot your server. Assume that you don’t know the root password, and use the appropriate mode to enter a root shell that doesn’t require a password. Set the root password to mypassword.
  • Set default values for new users. Set the default password validity to 90 days, and set the first UID that is used for new users to 2000.
  • Create users edwin and santos and make them members of the group livingopensource as a secondary group membership. Also, create users serene and alex and make them members of the group operations as a secondary group. Ensure that user santos has UID 1234 and cannot start an interactive shell.
  • Create shared group directories /groups/livingopensource and /groups/operations, and make sure the groups meet the following requirements:
  • Members of the group livingopensource have full access to their directory.
  • Members of the group operations have full access to their directory.
  • New files that are created in the group directory are group owned by the group owner of the parent directory.
  • Others have no access to the group directories.
  • Create a 2-GiB volume group with the name myvg, using 8-MiB physical extents. In this volume group, create a 500-MiB logical volume with the name mydata, and mount it persistently on the directory /mydata.
  • Find all files that are owned by user edwin and copy them to the directory/rootedwinfiles.
  • Schedule a task that runs the command touch /etc/motd every day from Monday through Friday at 2 a.m.
  • Add a new 10-GiB virtual disk to your virtual machine. On this disk, add a Stratis volume and mount it persistently.
  • Create user bob and set this user’s shell so that this user can only change the password and cannot do anything else.
  • Install the vsftpd service and ensure that it is started automatically at reboot.
  • Create a container that runs an HTTP server. Ensure that it mounts the host directory /httproot on the directory /var/www/html.
  • Configure this container such that it is automatically started on system boot as a system user service.
  • Create a directory with the name /users and ensure it contains the subdirectories linda and anna. Export this directory by using an NFS server.
  • Create users linda and anna and set their home directories to /home/users/linda and /home/users/anna. Make sure that while these users access their home directory, autofs is used to mount the NFS shares /users/linda and /users/anna from the same server.

 

Get Your Free Linux training!

Join our free Linux training and discover the power of open-source technology. Enhance your skills and boost your career! Learn Linux for Free!

Answers:

Reset the root password on boot

If you are unable to log in as a non-root user or do not belong to the administrative wheel group, you can reset the root password on boot by switching into a specialized chroot jail environment.

Procedure

Reboot the system and, on the GRUB 2 boot screen, press the e key to interrupt the boot process.

The kernel boot parameters appear.

load_video
set gfx_payload=keep
insmod gzio
linux ($root)/vmlinuz-5.14.0-70.22.1.e19_0.x86_64 root=/dev/mapper/rhel-root ro crash\
kernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv/swap rhgb quiet
initrd ($root)/initramfs-5.14.0-70.22.1.e19_0.x86_64.img $tuned_initrd

Go to the end of the line that starts with linux.

linux ($root)/vmlinuz-5.14.0-70.22.1.e19_0.x86_64 root=/dev/mapper/rhel-root ro crash\
kernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv/swap rhgb quiet

Press Ctrl+e to jump to the end of the line. Add rd.break to the end of the line that starts with linux.

linux ($root)/vmlinuz-5.14.0-70.22.1.e19_0.x86_64 root=/dev/mapper/rhel-root ro crash\
kernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv/swap rhgb quiet rd.break

Press Ctrl+x to start the system with the changed parameters. The switch_root prompt appears.

Remount the file system as writable:

mount -o remount,rw /sysroot

The file system is mounted as read-only in the /sysroot directory. Remounting the file system as writable allows you to change the password.

Enter the chroot environment:

chroot /sysroot

The sh-4.4# prompt appears.

Reset the root password:

passwd

Follow the instructions displayed by the command line to finalize the change of the root password.

Enable the SELinux relabeling process on the next system boot:

touch /.autorelabel

Exit the chroot environment: exit
Exit the switch_root prompt: exit
Wait until the SELinux relabeling process is finished. Note that relabeling a large disk might take a long time. The system reboots automatically when the process is complete.

Set default values for new users

To set default values for new users, such as the password validity and the first UID, you’ll need to modify the configuration files related to user management on your system. The steps may vary depending on your specific operating system and distribution. Here’s a general approach:

Log in as the root user or use a user account with administrative privileges.

Locate the configuration file for new user defaults. The file is /etc/login.defs. Use a text editor to open the file.

Find the parameter related to password validity (password aging) and set it to 90 days. In the configuration file, look for a line similar to:

PASS_MAX_DAYS 99999

Change it to:

PASS_MAX_DAYS 90

Find the parameter related to the first UID used for new users. Look for a line similar to:

FIRST_UID 1000

Change it to:

FIRST_UID 2000

Save the changes to the configuration file.

Note that the specific parameter names and locations of the configuration files may vary depending on your system. It’s important to consult the documentation or relevant resources for your specific operating system or distribution to ensure accuracy.

After modifying the configuration files, the new defaults will be applied to new users created on your system. Existing users will not be affected by these changes.

Remember to always exercise caution when modifying system configuration files, as incorrect changes can lead to unintended consequences. It is recommended to make a backup of the configuration file before making any modifications and to test the changes in a controlled environment.

Further reading:

10 useful Linux useradd command Examples

2 ways to list users in Linux

Create users

To create users and assign them to specific groups with secondary group memberships, you can use the user management commands available on your system. Here’s a general approach to achieve this:

Log in as the root user or use a user account with administrative privileges.

Create the user “edwin” and assign them to the “livingopensource” group as a secondary group:

useradd -G livingopensource edwin

Create the user “santos” with UID 1234, assign them to the “livingopensource” group as a secondary group, and prevent them from starting an interactive shell:

useradd -u 1234 -G livingopensource -s /usr/sbin/nologin santos

Create the user “serene” and assign them to the “operations” group as a secondary group:

useradd -G operations serene

Create the user “alex” and assign them to the “operations” group as a secondary group:

useradd -G operations alex

Verify that the users have been created and assigned to the correct groups by checking the system’s user and group configuration. You can use commands like cat /etc/passwd and cat /etc/group to display the user and group information.

Further reading:

How To Create Users In Linux – Step By Step Tutorial

3 Easy Ways to add user to group in Linux

Create directory 

To create shared group directories with the specified requirements, you can use the following steps:

Log in as the root user or use a user account with administrative privileges.

Create the group directories and set the appropriate ownership and permissions:

mkdir -p /groups/livingopensource
chown root:livingopensource /groups/livingopensource
chmod 770 /groups/livingopensource

mkdir -p /groups/operations
chown root:operations /groups/operations
chmod 770 /groups/operations

Set the group ownership inheritance for newly created files within the group directories:

chmod g+s /groups/livingopensource
chmod g+s /groups/operations

Further reading:

2 ways to create a directory in Linux

2 ways to check file permissions in Linux

Create volume in RHEL

To create a 2-GiB volume group with the name “myvg,” using 8-MiB physical extents, and then create a 500-MiB logical volume named “mydata” and mount it persistently on the directory “/mydata,” you can follow these steps:

Log in as the root user or use a user account with administrative privileges.

Create a physical volume using a block device or partition. For example, if the block device is /dev/sdb1:

pvcreate /dev/sdb1

Create the volume group named “myvg” using the physical volume(s):

vgcreate myvg /dev/sdb1

Adjust the command if you have multiple physical volumes to include in the volume group.

Create a logical volume named “mydata” within the volume group “myvg” with a size of 500 MiB:

lvcreate -L 500M -n mydata myvg

Format the logical volume with the desired filesystem, such as ext4:

mkfs.ext4 /dev/myvg/mydata

Create the mount point directory:

mkdir /mydata

Edit the /etc/fstab file to add an entry for the persistent mount:

echo ‘/dev/myvg/mydata /mydata ext4 defaults 0 0’ >> /etc/fstab

Mount the logical volume:

mount /mydata

If you want to mount all filesystems specified in /etc/fstab, you can use the mount -a command.

After following these steps, the logical volume “mydata” within the volume group “myvg” will be created, formatted, mounted, and configured for persistent mounting on the “/mydata” directory. Adjust the commands and parameters based on your specific system setup if needed.

Find files in RHEL

To find all files owned by user “edwin” and copy them to the directory “/rootedwinfiles,” you can use the find command along with the cp command. Follow these steps:

Log in as the root user or use a user account with administrative privileges.

Create the destination directory “/rootedwinfiles” if it doesn’t already exist:

mkdir /rootedwinfiles

Use the find command to locate all files owned by user “edwin” and copy them to the destination directory:

find / -type f -user edwin -exec cp {} /rootedwinfiles/ \;

This command will search the entire file system (“/”) for files owned by the user “edwin” (-user edwin) and execute the cp command to copy each file to the “/rootedwinfiles” directory.

Note that the search may take some time depending on the size of your file system and the number of files owned by “edwin.”

After executing these steps, all files owned by user “edwin” will be copied to the “/rootedwinfiles” directory. Adjust the commands and directories according to your specific needs.

Further reading:

20 Advanced Linux Find Command Examples

Schedule tasks with crontab in RHEL

To schedule a task that runs the command touch /etc/motd every day from Monday through Friday at 2 a.m., you can use the cron utility. Follow these steps:

Log in as the root user or use a user account with administrative privileges.

Open the cron table for editing by executing the following command:

crontab -e

If prompted, choose a text editor to edit the cron table.

Add the following line to the cron table to schedule the task:

0 2 * * 1-5 touch /etc/motd

This line specifies that the touch /etc/motd command should run at 2 a.m. (0 2) every day from Monday through Friday (1-5). The * denotes every possible value for the remaining fields (month, day of the month, and day of the week).

Save the changes and exit the text editor.

Cron will now execute the touch /etc/motd command at 2 a.m. every day from Monday through Friday. The /etc/motd file will be updated with the current timestamp.

Make sure to test the cron job to ensure it runs as expected. Also, keep in mind that the system’s time zone should be set correctly for the scheduled task to run at the desired time.