RHCSA Exam — Complete Lab Task Solutions
01 — RHEL Installation
Lab 1.1: Install a Second Server
This lab is performed during the RHEL installer (Anaconda) GUI/CLI. The key steps are:
- Boot from the RHEL 9 installation media.
- In the Installation Summary:
- Keyboard → Set your preferred layout.
- Installation Source → Point to the RHEL 9 ISO or network repo.
- Software Selection → Choose Minimal Install.
- Network & Host Name → Click
e1000(or your interface) → Set IPv4 to Automatic (DHCP). Set Host Name toserver2.example.com→ click Done. - Installation Destination → Select the target disk → Done (LVM is created automatically by default).
- Root Password → Set a strong password.
- User Creation → Create the
studentuser with sudo access.
- Click Begin Installation and wait.
- After installation, reboot.
# After reboot, verify:
hostnamectl status
# Should show: Static hostname: server2.example.com
ip addr show
# Should show an IP obtained via DHCP
dnf list installed | grep -c "^"
# Minimal install will have far fewer packages than "Server with GUI"
Why this works: The Anaconda installer handles partitioning, LVM creation, network config, and package installation. “Minimal Install” selects only the base environment, which is ideal for a practice server. DHCP is configured in the Network screen. The hostname is set via hostnamectl internally by the installer.
02 — Essential CLI Tools
Lab 2.1: CLI Practice
Task 1: Set COLOR=red in every subshell
# Add to ~/.bashrc so every interactive shell inherits it
echo 'export COLOR=red' >> ~/.bashrc
# Verify in a new subshell
bash -c 'echo $COLOR'
# Output: red
Why this works: ~/.bashrc is sourced by every interactive non-login Bash shell. Using export makes the variable available to child processes (subshells).
Task 2: Find the command that changes a user password; check if root is required
man -k password | grep change
# Look for: passwd(1)
man passwd | head -30
# The manual states: "Only the superuser may change a password for another user."
# Regular users can change their own password; root is required for others.
Why this works: man -k searches the short descriptions of all man pages. The passwd man page documents that only root can change another user’s password.
Task 3: Redirect both stdout and stderr to /tmp/lsoutput
cd ~
ls -al wergihl * > /tmp/lsoutput 2>&1
Why this works: > redirects stdout to the file. 2>&1 redirects stderr (file descriptor 2) to wherever stdout is currently pointing (the file). The order matters — 2>&1 must come AFTER > file.
03 — File Management
Lab 3.1: File Management Practice
# Log in as student, then switch to root
sudo -i
# Create archive of /home and /etc in /root
tar cf /root/essentials.tar -C / home -C / etc
# Copy archive to /tmp
cp /root/essentials.tar /tmp/essentials.tar
# Create a hard link in /
ln /tmp/essentials.tar /essentials.tar
# Rename /essentials.tar to /archive.tar
mv /essentials.tar /archive.tar
# Create a symbolic link in root's home
ln -s /archive.tar /root/link.tar
# Remove /archive.tar — the hard link in /tmp still works (same inode)
rm /archive.tar
# Verify: /tmp/essentials.tar still exists and is valid
ls -li /tmp/essentials.tar /root/link.tar
# /root/link.tar will now be a broken symlink (target /archive.tar is gone)
# Remove the broken symbolic link
rm /root/link.tar
# Compress the archive
gzip /root/essentials.tar
# Result: /root/essentials.tar.gz
Why this works:
tar cfcreates an archive;-Cchanges directory before processing.- A hard link (
ln) shares the same inode — deleting one name doesn’t affect the other. - A symbolic link (
ln -s) is a pointer — deleting the target breaks the link. gzipcompresses the file in place, producing.tar.gz.
04 — Text File Manipulation
Lab 4.1: Text Processing Practice
Task 1: Two ways to show line 5 from /etc/passwd
# Method 1: head + tail
head -5 /etc/passwd | tail -1
# Method 2: sed
sed -n '5p' /etc/passwd
Why this works: head -5 outputs the first 5 lines, then tail -1 picks the last one (line 5). sed -n '5p' prints only line 5 (-n suppresses default output, 5p prints line 5).
Task 2: Find text files containing the current IP address
# Get current IP
MYIP=$(hostname -I | awk '{print $1}')
# Search all text files — a simple string match is sufficient (no regex needed)
grep -rl "$MYIP" /etc/ /var/log/ /home/ 2>/dev/null
Why this works: hostname -I returns the IP. grep -r recurses, -l lists only filenames. An IP like 192.168.4.210 can be matched literally — no regex required.
Task 3: Revert a sed replacement (“Administrator” → “root”)
# If you ran: sed -i 's/Administrator/root/g' somefile
# Revert by reversing the substitution (if "root" was not originally present):
sed -i 's/root/Administrator/g' somefile
# Better approach: always keep a backup
# sed -i.bak 's/Administrator/root/g' somefile
# Then restore: cp somefile.bak somefile
Why this works: sed -i edits in place. Reversing the substitution works only if the replacement string wasn’t already in the file. The best practice is to use -i.bak to keep a backup.
Task 4: Show the process with the heaviest memory utilization first
ps aux --sort=-%mem | head -5
Why this works: --sort=-%mem sorts by memory percentage in descending order. head -5 shows the top 5.
Task 5: Filter the sixth column of ps aux
ps aux | awk '{print $6}'
Why this works: awk '{print $6}' prints the 6th whitespace-delimited field (RSS — resident set size in kilobytes).
Task 6: Delete the sixth line from ~/myfile
sed -i '6d' ~/myfile
Why this works: sed -i '6d' deletes line 6 in place.
05 — Connecting to RHEL
Lab 5.1: Local Console Practice
# Disable graphical interface (set default target to multi-user)
sudo systemctl set-default multi-user.target
sudo reboot
# After reboot, you'll see a text-based login prompt.
# Activate tty6:
# Press: Alt + F6
# Switch back to graphical interface:
# First re-enable the GUI target:
sudo systemctl set-default graphical.target
sudo reboot
# Or without reboot, press Alt + F2 (or F1) to return to the GUI tty
Why this works: systemctl set-default changes the default systemd target. multi-user.target = text mode, graphical.target = GUI. Virtual consoles are accessed via Alt+F1 through Alt+F6.
Lab 5.2: SSH Practice
# On server2, connect to server1
ssh student@server1.example.com
# Enable X11 forwarding for graphical applications
ssh -X student@server1.example.com
# Set up key-based authentication
# On server2 (client):
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N ""
ssh-copy-id student@server1.example.com
# Now connect without password:
ssh student@server1.example.com
Why this works: ssh-keygen generates a key pair. ssh-copy-id copies the public key to the server’s ~/.ssh/authorized_keys. The -X flag enables X11 forwarding so GUI apps display on the client.
06 — Managing Software
Lab 9.1: Package Management Practice
# Create /myrepo and copy RPMs from installation media
mkdir -p /myrepo
mount /dev/sr0 /mnt # Mount installation ISO
cp -r /mnt/BaseOS/Packages/* /myrepo/ 2>/dev/null
cp -r /mnt/AppStream/Packages/* /myrepo/ 2>/dev/null
umount /mnt
# Create a functional repository
dnf install -y createrepo
createrepo /myrepo
# Configure the server to use it
cat > /etc/yum.repos.d/myrepo.repo << 'EOF'
[myrepo]
name=My Local Repository
baseurl=file:///myrepo
enabled=1
gpgcheck=0
EOF
# List repositories
dnf repolist
# Search for the cache-only DNS name server (caching-nameserver group / bind package)
dnf search caching-nameserver
# Or: dnf search bind
# Extensive query of the package (e.g., bind)
dnf repoquery -l bind # List files
dnf repoquery -R bind # List dependencies (requires)
dnf repoquery -d bind # List documentation
dnf repoquery -c bind # List config files
# Check for scripts in the RPM (download without installing)
dnf install --downloadonly --downloaddir=/tmp bind
rpm -qP /tmp/bind-*.rpm | grep -i script
# Or more specifically:
rpmqp -i /tmp/bind-*.rpm | grep -A5 "Script"
# Install the package
dnf install -y bind
# Remove the package
dnf remove -y bind
Why this works: createrepo builds the repository metadata (repodata/). A .repo file tells dnf where to find packages. dnf repoquery inspects packages without installing. --downloadonly downloads the RPM for inspection. rpm -qP queries the package for scripts.
07 — Scripting
Lab 19.1: Script Writing Practice
Script 1 — Argument Handler
cat > /root/arg_handler.sh << 'EOF'
#!/bin/bash
case "$1" in
one)
touch /tmp/one
;;
two)
echo "Message body" | mail -s "two" root
;;
*)
echo "Usage: $0 {one|two}"
exit 1
;;
esac
exit 0
EOF
chmod +x /root/arg_handler.sh
Why this works: The case statement matches the first argument ($1). touch creates the file. mail -s "two" root sends an email with subject “two” to root. exit 0 signals successful completion.
Script 2 — Countdown Timer
cat > /root/countdown.sh << 'EOF'
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: $0 <minutes>"
exit 1
fi
seconds=$(( $1 * 60 ))
while [ $seconds -gt 0 ]; do
echo "there are $seconds seconds remaining"
sleep 1
seconds=$(( seconds - 1 ))
done
echo "time is over"
exit 0
EOF
chmod +x /root/countdown.sh
Why this works: $1 is the minutes argument. It’s converted to seconds. The while loop decrements each second with sleep 1. When seconds reaches 0, the loop exits and prints “time is over”.
08 — Managing Processes
Lab 10.1: Process Management Practice
# Launch three dd processes in the background
dd if=/dev/zero of=/dev/null &
dd if=/dev/zero of=/dev/null &
dd if=/dev/zero of=/dev/null &
# Check jobs
jobs -l
# Increase priority of one dd process to nice -5
# Find the PID of the first dd
DD_PID=$(pgrep -o dd)
renice -5 -p $DD_PID
# Change the same process priority to -15
renice -15 -p $DD_PID
# Verify the nice values
ps -o pid,ni,comm -p $DD_PID
# Kill all dd processes
pkill dd
# Or: killall dd
# Ensure tuned is installed and active
dnf install -y tuned
systemctl enable --now tuned
# Set throughput-performance profile
tuned-adm profile throughput-performance
# Verify
tuned-adm active
Why this works: & backgrounds a process. renice changes the priority of a running process (lower = higher priority). pkill kills processes by name. tuned-adm manages performance profiles.
09 — Systemd
Lab 11.1: Systemd Practice
# Install vsftpd and httpd
dnf install -y vsftpd httpd
# Set default systemctl editor to vim
systemctl alias editor vim
# Or set EDITOR environment variable:
echo 'export EDITOR=vim' >> ~/.bashrc
# Edit httpd.service to auto-start vsftpd
systemctl edit httpd.service
# Add the following content in the editor:
# [Unit]
# Wants=vsftpd.service
# Configure httpd to restart 10 seconds after failure
systemctl edit httpd.service
# Add/modify:
# [Service]
# Restart=on-failure
# RestartSec=10
# Reload and enable
systemctl daemon-reload
systemctl enable --now httpd
Why this works: systemctl edit creates an override drop-in file under /etc/systemd/system/httpd.service.d/. Wants= creates a weak dependency (httpd wants vsftpd but won’t fail if vsftpd fails). Restart=on-failure with RestartSec=10 restarts the service 10 seconds after a crash.
10 — Scheduling Tasks
Lab 12.1: Task Scheduling Practice
# Cron job: update all software every evening at 11 p.m.
echo '0 23 * * * dnf update -y' | crontab -
# Verify
crontab -l
# Schedule reboot at 3 a.m. tomorrow using at
at 3:00 AM tomorrow
# Then type:
reboot
# Press Ctrl+D to close the at shell
# Verify at job
atq
# Systemd timer: start vsftpd 5 minutes after boot
# Create the service unit
cat > /etc/systemd/system/vsftpd-boot.service << 'EOF'
[Unit]
Description=Start vsftpd 5 minutes after boot
[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl start vsftpd.service
EOF
# Create the timer unit
cat > /etc/systemd/system/vsftpd-boot.timer << 'EOF'
[Unit]
Description=Trigger vsftpd 5 minutes after boot
[Timer]
OnBootSec=5min
Unit=vsftpd-boot.service
[Install]
WantedBy=timers.target
EOF
# Enable and start the timer
systemctl daemon-reload
systemctl enable --now vsftpd-boot.timer
# Verify
systemctl list-timers vsftpd-boot.timer
Why this works: crontab schedules recurring jobs (minute hour day month weekday). at schedules one-time jobs. A systemd OnBootSec=5min timer triggers the associated service 5 minutes after boot.
11 — Configuring Logging
Lab 13.1: Logging Practice
# Make systemd journal persistent
mkdir -p /var/log/journal
systemctl restart systemd-journald
# Verify persistence
journalctl --verify
# Create rsyslog config to write info-priority messages
cat > /etc/rsyslog.d/99-info.conf << 'EOF'
*.info /var/log/messages.info
EOF
# Restart rsyslog
systemctl restart rsyslog
# Configure logrotate to keep 10 old versions
cat > /etc/logrotate.d/messages-info << 'EOF'
/var/log/messages.info {
rotate 10
daily
missingok
notifempty
compress
delaycompress
postrotate
/usr/bin/systemctl restart rsyslog > /dev/null 2>&1 || true
endscript
}
EOF
Why this works: /var/log/journal/ must exist for persistent journal storage. rsyslog reads config from /etc/rsyslog.d/. The *.info rule catches all facilities at info priority and above. logrotate’s rotate 10 keeps 10 old versions.
12 — Managing Boot Procedure
Lab 17.1: Boot Target Practice
# Set default boot target to multi-user.target
systemctl set-default multi-user.target
# Verify (shows symlink target)
systemctl get-default
# Output: multi-user.target
# Reboot and verify
reboot
# After reboot, verify:
systemctl get-default
systemctl list-units --type=target --state=active
Why this works: systemctl set-default changes the symlink /etc/systemd/system/default.target to point to the specified target.
Lab 17.2: GRUB 2 Practice
# Edit GRUB configuration
vim /etc/default/grub
# Modify the GRUB_CMDLINE_LINUX line — remove "rhgb quiet":
# Before: GRUB_CMDLINE_LINUX="crashkernel=auto rd.auto=1 rhgb quiet"
# After: GRUB_CMDLINE_LINUX="crashkernel=auto rd.auto=1"
# Regenerate GRUB configuration
# For BIOS systems:
grub2-mkconfig -o /boot/grub2/grub.cfg
# For UEFI systems:
grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
# Reboot to verify boot messages are visible
reboot
Why this works: rhgb (Red Hat Graphical Boot) and quiet suppress boot messages. Removing them from GRUB_CMDLINE_LINUX and regenerating grub.cfg makes boot messages visible.
13 — Time Services
Lab 25.1: Time Services Practice
# Compare hardware time and system time
timedatectl status
# Check if there's a difference
hwclock --show # Hardware clock
date # System clock
# Synchronize hardware clock to system clock
timedatectl set-ntp true
hwclock --systohc # Write system time to hardware clock
# Set time zone to Boston (America/New_York)
timedatectl list-timezones | grep New_York
timedatectl set-timezone America/New_York
# Verify
timedatectl status
# Should show:
# Time zone: America/New_York (EDT, -0400)
# NTP enabled: yes
Why this works: timedatectl is the recommended RHEL 9 tool for time management. set-ntp true enables chrony synchronization. hwclock --systohc syncs hardware clock to system time. set-timezone changes the timezone.
14 — Managing Mounting Storage
Lab 14.1: Mounting Storage Practice
# Assume the new disk is /dev/vdb (adjust based on your environment)
# Create two 100 MiB partitions
fdisk /dev/vdb << 'EOF'
n
p
1
+100M
t
1
82
n
p
2
+100M
w
EOF
# Format partition 1 as swap
mkswap /dev/vdb1
# Format partition 2 as Ext4
mkfs.ext4 /dev/vdb2
# Create mount point
mkdir -p /mounts/data
# Get UUIDs
blkid /dev/vdb1
blkid /dev/vdb2
# Add to /etc/fstab for persistent mounting
UUID_SWAP=$(blkid -s UUID -o value /dev/vdb1)
UUID_EXT4=$(blkid -s UUID -o value /dev/vdb2)
echo "UUID=$UUID_SWAP none swap sw 0 0" >> /etc/fstab
echo "UUID=$UUID_EXT4 /mounts/data ext4 defaults 0 0" >> /etc/fstab
# Activate
swapon -a
mount -a
# Verify
swapon --show
df -hT /mounts/data
# Reboot and verify
reboot
# After reboot:
swapon --show
df -hT /mounts/data
Why this works: fdisk creates partitions. Type 82 marks swap. mkswap and mkfs.ext4 format the partitions. Using UUIDs in /etc/fstab ensures stable identification across reboots.
15 — Managing Logical Storage
Lab 15.1: LVM Practice
# Assume /dev/vdb is available (or use a loopback device)
# Create a partition for LVM
fdisk /dev/vdb << 'EOF'
n
p
1
+500M
t
1
8e
w
EOF
# Create Physical Volume
pvcreate /dev/vdb1
# Create Volume Group
vgcreate vgdata /dev/vdb1
# Create Logical Volume of 500 MB
lvcreate -L 500M -n lvgroup vgdata
# Format with XFS
mkfs.xfs /dev/vgdata/lvgroup
# Create mount point and mount
mkdir -p /groups
echo "/dev/vgdata/lvgroup /groups xfs defaults 0 0" >> /etc/fstab
mount -a
# Verify
df -hT /groups
# Reboot and verify
reboot
df -hT /groups
# After reboot, extend by 250 MB
# First ensure there's space — if not, add another partition/device
# Assuming we have space in the VG:
lvextend -L +250M /dev/vgdata/lvgroup
# XFS auto-resizes with the LV (RHEL 9 feature)
# Verify
df -hT /groups
# The size should now reflect the extension
Why this works: LVM layers: PV → VG → LV. lvextend grows the logical volume. XFS on RHEL 9 automatically grows the filesystem when the LV is extended (no separate xfs_growfs needed in most cases, but you can run it explicitly: xfs_growfs /groups).
Lab 15.2: Stratis Practice
# Install Stratis
dnf install -y stratisd stratis-cli
# Enable and start stratisd
systemctl enable --now stratisd
# Create block devices (loopback for practice)
# Or use actual disks like /dev/vdc, /dev/vdd
truncate -s 5G /tmp/stratis-disk1
losetup /dev/loop0 /tmp/stratis-disk1
# Create a Stratis pool
stratis pool create mypool /dev/loop0
# Create two file systems
stratis fs create mypool fs1
stratis fs create mypool fs2
# Mount them
mkdir -p /stratis/fs1 /stratis/fs2
stratis fs list mypool
# Get the mount paths: /stratis/mypool/fs1 and /stratis/mypool/fs2
# For auto-mount via /etc/fstab, use the stratis paths:
echo "/stratis/mypool/fs1 /stratis/fs1 fuse.stratisfs defaults 0 0" >> /etc/fstab
echo "/stratis/mypool/fs2 /stratis/fs2 fuse.stratisfs defaults 0 0" >> /etc/fstab
# Add another block device to the pool
truncate -s 5G /tmp/stratis-disk2
losetup /dev/loop1 /tmp/stratis-disk2
stratis pool add mypool /dev/loop1
# Verify pool size
stratis pool list
# Reboot and verify
reboot
df -hT /stratis/fs1 /stratis/fs2
Why this works: Stratis is RHEL 9’s modern storage management tool. stratis pool create creates a pool from block devices. stratis fs create creates filesystems within the pool. Adding devices with stratis pool add extends the pool.
16 — Managing Network Storage
Lab 24.1: Network Storage Practice
On server2 (NFS Server):
# Install NFS server packages
dnf install -y nfs-utils
# Enable and start NFS services
systemctl enable --now nfs-server rpc-bind
# Export /home directory
cat > /etc/exports << 'EOF'
/home *(rw,sync,no_root_squash,no_subtree_check)
EOF
# Export the share
exportfs -ra
# Verify
showmount -e localhost
# Open firewall
firewall-cmd --permanent --add-service=nfs
firewall-cmd --permanent --add-service=mountd
firewall-cmd --permanent --add-service=rpc-bind
firewall-cmd --reload
Why this works: nfs-utils provides NFS server. /etc/exports defines shared directories. exportfs -ra re-exports all shares. The firewall must allow NFS, mountd, and rpc-bind services.
On server1 (NFS Client with Automount):
# Install autofs and NFS client
dnf install -y autofs nfs-utils
# Create automount configuration
cat > /etc/auto.master.d/home.autofs << 'EOF'
/home /etc/auto.home --timeout=60
EOF
cat > /etc/auto.home << 'EOF'
* -fstype=nfs,rw,sync server2.example.com:/home/&
EOF
# Enable and start autofs
systemctl enable --now autofs
# Verify — accessing a user's home should trigger the mount
ls /home/student
# This should show the contents from server2's /home/student
Why this works: autofs dynamically mounts filesystems on access. /etc/auto.master.d/ defines mount points. The wildcard * with & substitutes the username, so /home/joana mounts server2:/home/joana.
17 — Managing Kernel
Lab 16.1: Kernel Practice
# Check for new kernel version
dnf check-update kernel
# Install new kernel if available
dnf install -y kernel
# Reboot to use the new kernel
reboot
# After reboot, verify new kernel
uname -r
# Show recent kernel events
dmesg | tail -30
# Or: journalctl -k --since "10 minutes ago"
# Find the kernel module used by your network card
lspci -k | grep -A3 Ethernet
# Note the module name (e.g., e1000, virtio_net)
# Check if the module is loaded
lsmod | grep <module_name>
# Find configurable options for the module
modinfo <module_name> | grep param
# Load a module option manually (example: setting interrupt coalescing)
rmmod <module_name>
modprobe <module_name> <parameter>=<value>
# Make the change persistent
cat > /etc/modprobe.d/<module_name>.conf << 'EOF'
options <module_name> <parameter>=<value>
EOF
Why this works: dnf check-update kernel checks for updates. dmesg shows kernel ring buffer messages. lspci -k shows kernel drivers in use. modinfo lists module parameters. /etc/modprobe.d/ provides persistent module configuration.
18 — Managing Networking
Lab 8.1: Networking Practice
# Set FQDN hostnames
# On server1:
hostnamectl set-hostname server1.example.com
# On server2:
hostnamectl set-hostname server2.example.com
# Verify
hostnamectl status
# Configure network using nmtui (text UI)
nmtui
# Or using nmcli for fixed IP on server1:
nmcli connection modify <connection-name> \
ipv4.method manual \
ipv4.addresses 192.168.4.210/24 \
ipv4.gateway 192.168.4.1 \
ipv4.dns "8.8.8.8 8.8.4.4" \
ipv4.dns-search "example.com"
# Activate the connection
nmcli connection up <connection-name>
# On server2, set fixed IP:
nmcli connection modify <connection-name> \
ipv4.method manual \
ipv4.addresses 192.168.4.220/24 \
ipv4.gateway 192.168.4.1 \
ipv4.dns "8.8.8.8 8.8.4.4"
nmcli connection up <connection-name>
# Verify connectivity
ping -c 3 server2.example.com # From server1
ping -c 3 server1.example.com # From server2
# Configure DHCP server for router and DNS (if running dnsmasq or similar)
dnf install -y dnsmasq
cat > /etc/dnsmasq.conf << 'EOF'
interface=eth0
dhcp-range=192.168.4.100,192.168.4.200,12h
dhcp-option=3,192.168.4.1
dhcp-option=6,8.8.8.8,8.8.4.4
EOF
systemctl enable --now dnsmasq
Why this works: hostnamectl sets the hostname persistently. nmcli configures NetworkManager connections. nmtui provides a text-based UI. dnsmasq provides DHCP and DNS services.
19 — Managing Firewall
Lab 23.1: Firewall Practice
# Ensure firewalld is running
systemctl enable --now firewalld
# Add services permanently
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --permanent --add-service=ftp
firewall-cmd --permanent --add-service=ssh
# Reload to apply permanent changes
firewall-cmd --reload
# Verify
firewall-cmd --list-all
# Check all zones
firewall-cmd --list-all-zones
Why this works: firewall-cmd --permanent writes to the persistent configuration. --add-service uses predefined service definitions (which include the correct ports and protocols). --reload applies permanent changes to the runtime configuration.
20 — Managing Users and Groups
Lab 6.1: Shared Group Environment
# Create groups
groupadd sales
groupadd account
# Create users with private groups (primary group = same name as user)
useradd joana
useradd john
useradd laura
useradd beatrix
# Add secondary group memberships
usermod -aG sales joana
usermod -aG sales john
usermod -aG account laura
usermod -aG account beatrix
# Verify group memberships
groups joana
groups john
groups laura
groups beatrix
# Set password policy: change password every 90 days
# Apply to all four users
for user in joana john laura beatrix; do
chage -M 90 $user
done
# Verify
chage -l joana
# Should show: Maximum number of days between password change: 90
Why this works: useradd creates a user with a private group by default. usermod -aG appends secondary groups. chage -M 90 sets maximum password age to 90 days.
Lab 6.2: Sudo Configuration
# Create user bill
useradd bill
echo "bill:password123" | chpasswd
# Create sudoers drop-in file
cat > /etc/sudoers.d/bill << 'EOF'
bill ALL=(ALL) /usr/sbin/usermod [!-a]*, !/usr/sbin/usermod *root*, /usr/bin/passwd [!r]*, !/usr/bin/passwd root
EOF
# Validate sudoers syntax
visudo -c
# Test: bill can run usermod and passwd but NOT for root
sudo -u bill sudo passwd joana # Should work
sudo -u bill sudo passwd root # Should be denied
Why this works: /etc/sudoers.d/ allows drop-in sudo rules. The ! prefix negates a command. passwd [!r]* allows passwd for any user except those starting with ‘r’. !/usr/bin/passwd root explicitly denies root password changes.
21 — Managing Permissions
Lab 7.1: Permissions Practice
# Create directories
mkdir -p /data/account /data/sales
# Set group ownership
chgrp sales /data/sales
chgrp account /data/account
# Set permissions: rwx for user and group, nothing for others (770)
chmod 770 /data/sales /data/account
# Set SGID so new files inherit the group owner
chmod g+s /data/sales /data/account
# Set sticky bit so users can only delete their own files
chmod +t /data/sales /data/account
# Verify
ls -ld /data/sales /data/account
# Expected: drwxrws--T /data/sales and drwxrws--T /data/account
Why this works:
770= rwx for owner and group, no access for others.g+s(SGID) makes new files/dirs inherit the directory’s group.+t(sticky bit) restricts deletion to the file’s owner, root, or the directory’s owner.
22 — Managing SSH
Lab 20.1: SSH Hardening Practice
# Edit SSH server configuration
vim /etc/ssh/sshd_config
# Set inactive session timeout to 1 hour (3600 seconds)
# Add/modify these lines:
# ClientAliveInterval 300
# ClientAliveCountMax 12
# (300 * 12 = 3600 seconds = 1 hour)
# Listen on port 2022 only
# Port 2022
# Allow only user lisa
# AllowUsers lisa
# Disable root login (best practice)
# PermitRootLogin no
# Create user lisa if not exists
useradd lisa
echo "lisa:password123" | chpasswd
# Restart SSH
systemctl restart sshd
# Configure firewall for new port
firewall-cmd --permanent --add-port=2022/tcp
firewall-cmd --permanent --remove-service=ssh # Remove default port 22
firewall-cmd --reload
# Configure SELinux for non-default SSH port
semanage port -a -t ssh_port_t -p tcp 2022
# If port already defined:
# semanage port -m -t ssh_port_t -p tcp 2022
# Verify SELinux port
semanage port -l | grep ssh
# Test from server2
ssh -p 2022 lisa@server1.example.com
Why this works: ClientAliveInterval × ClientAliveCountMax = max idle time. AllowUsers restricts login. semanage port tells SELinux that port 2022 is a valid SSH port. Firewall must allow the new port.
23 — Managing SELinux
Lab 22.1: SELinux Practice
# Create /web directory and index.html
mkdir -p /web
echo "welcome to my web server" > /web/index.html
# Change Apache document root
sed -i 's|DocumentRoot "/var/www/html"|DocumentRoot "/web"|' /etc/httpd/conf/httpd.conf
sed -i 's|Directory "/var/www/html"|Directory "/web"|' /etc/httpd/conf/httpd.conf
# Restart httpd — it will fail due to SELinux
systemctl restart httpd
# Diagnose SELinux denials
ausearch -m avc -ts recent
# Or: grep httpd /var/log/audit/audit.log
# Fix: Set the correct SELinux context on /web
chcon -R -t httpd_sys_content_t /web
# Make it persistent with semanage
semanage fcontext -a -t httpd_sys_content_t "/web(/.*)?"
restorecon -Rv /web
# Restart httpd
systemctl restart httpd
# Test
curl http://localhost
# Create hosts file in root's home
cat > /root/hosts << 'EOF'
192.168.4.200 labipa.example.com
192.168.4.210 server1.example.com
192.168.4.220 server2.example.com
EOF
# Move to /etc
mv /root/hosts /etc/hosts
# Restore correct SELinux context
restorecon -v /etc/hosts
# Verify context
ls -Z /etc/hosts
# Should show: system_u:object_r:etc_t:s0
Why this works: SELinux denies httpd access to /web because it lacks the httpd_sys_content_t label. chcon changes the context immediately; semanage fcontext + restorecon makes it persistent. Moving files to /etc requires restoring the etc_t context.
24 — Managing Troubleshooting
Lab 18.1: Troubleshooting Practice
# Task 1: Reset root password via emergency mode
# Reboot and at the GRUB menu:
# - Press 'e' to edit the kernel entry
# - Find the line starting with 'linux'
# - Add 'rw init=/bin/bash' at the end
# - Press Ctrl+X to boot
# In the bash shell:
mount -o remount,rw / # If not already rw
echo "newrootpassword" | chpasswd
# If SELinux is enforcing, create the .autorelabel file:
touch /.autorelabel
# Reboot:
exec /sbin/init
# Or: Ctrl+Alt+Del
# Task 2: Fix broken /etc/fstab
# After reboot with broken fstab, you'll get an emergency shell:
# View the error:
journalctl -xb
# Fix the fstab entry:
vim /etc/fstab
# Correct the device name
# Then:
exit # To continue boot
# Or: systemctl default
# Task 3: Rescue disk
# Boot from installation media → Troubleshooting → Rescue a RHEL system
# The rescue environment chroots into your system:
chroot /mnt/sysimage
# Now you can fix anything
# Task 4: Re-create initramfs
dracut --force --regenerate-all
# Verify
ls -lh /boot/initramfs-*.img
Why this works: Adding init=/bin/bash to the kernel line bypasses the normal boot process. /.autorelabel triggers a full SELinux relabel on next boot. dracut --force rebuilds the initramfs for all installed kernels.
25 — Managing Apache
Lab 21.1: Apache Practice
# Install Apache
dnf install -y httpd
# Enable and start
systemctl enable --now httpd
# Create the welcome page
echo "Welcome to my web server" > /var/www/html/index.html
# Allow through firewall
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
# Verify with curl
curl http://localhost
# Output: Welcome to my web server
# Install Apache manual
dnf install -y httpd-manual
# Test access to /manual
curl http://localhost/manual
# Should return the Apache manual HTML
# In a browser, navigate to: http://server1.example.com/manual
Why this works: httpd is the Apache package on RHEL. The default document root is /var/www/html. httpd-manual installs the documentation under the /manual URL alias.
26 — Managing Containers
Lab 26.1: Containers Practice
# Install podman
dnf install -y podman
# Log in to Red Hat container registry
podman login registry.redhat.io
# Enter your Red Hat credentials
# Download the mariadb image
podman pull registry.redhat.io/rhel9/mariadb-105
# Create host directory for data
mkdir -p /opt/mariadb
# Start the mariadb container
podman run -d \
--name mariadb \
-p 3206:3306 \
-e MYSQL_ROOT_PASSWORD="password" \
-e MYSQL_DATABASE=mydb \
-v /opt/mariadb:/var/lib/mysql:Z \
--restart=always \
registry.redhat.io/rhel9/mariadb-105
# Verify container is running
podman ps
# Test connectivity
podman exec mariadb mysql -u root -ppassword -e "SHOW DATABASES;"
# Generate systemd unit file for auto-start
podman generate systemd --new --name mariadb --files --restart-policy=always
# This creates: container-mariadb.service and install.container-mariadb.sh
# Move to user systemd directory:
mv container-mariadb.service ~/.config/systemd/user/
# Enable the unit
systemctl --user enable container-mariadb.service
# For system-wide (not just user login), also enable linger:
loginctl enable-user $(whoami)
# This ensures user services start at boot, not just on login
Why this works: podman is RHEL 9’s container engine. -p 3206:3306 maps host port 3206 to container port 3306. -e sets environment variables. -v ...:Z sets the correct SELinux context for bind mounts. podman generate systemd creates a systemd unit for persistent container management. loginctl enable-user enables user services at boot.