RHCSA Rapid Track
RHCSA Rapid Track
RHCSA Rapid Track
---------------------------------------------------------------------------------------------------------------------------------------
Version 24.11
Ahmed Abdelwahed
ahmed@abdelwahed.me
LinkedIn
-------------------------------------------------------------------------------------------------------------------------------------
www.abdelwahed.me
RHCSA Rapid Track | Quick Guide
---------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------
www.abdelwahed.me
RHCSA Rapid Track | Quick Guide
---------------------------------------------------------------------------------------------------------------------------------------
Monitoring Files
• tail -f /var/log/messages Monitors a system log file in real-time.
File Maintenance Commands
Copying Files
• cp file1 /media/file4 Copies and renames a file with interactive prompts.
• cp -f /etc/*.conf /home/data Copies all .conf files, overwriting existing ones without prompting.
Redirection
• > Redirects stdout to a file.
• >> Appends stdout to a file.
• cat passwd > passwd_orig Redirects input to output.
• df -h > newfile Overwrites file content.
• cat /dev/null > ahmedfile Deletes file content.
• echo “wooooow” > passwd Overwrites content.
• echo “wooow” >> passwd Appends content.
-------------------------------------------------------------------------------------------------------------------------------------
www.abdelwahed.me
RHCSA Rapid Track | Quick Guide
---------------------------------------------------------------------------------------------------------------------------------------
• Before Cursor i
• New Line Below o
• New Line Above O
• Start of Line I
• After Cursor a
• End of Line A
Copying and Pasting
Deleting
• Delete Letter/Word/Line dl, dw, dd
• Delete Multiple Lines 20dd
• Delete to End of Line/File d$, dG
-------------------------------------------------------------------------------------------------------------------------------------
www.abdelwahed.me
RHCSA Rapid Track | Quick Guide
---------------------------------------------------------------------------------------------------------------------------------------
Changing Text
Execute Mode
• Save and Exit x, wq
• Force Exit q!
• Highlight Search se hlsearch, se nohlsearch
• Substitute Words %s/install/config/g
• Delete Lines $d, 1,9d, %d
• Add Empty Lines %s/$/\r/g
Visual Mode
• Use Ctrl+V > Shift+I > # > Esc for commenting multiple lines.
• Use Ctrl+V > y copy multiple lines.
• Use Ctrl+V > d delete multiple lines.
Vim Tips
• Lock and Unlock ctrl+s, ctrl+q
• Add New Screens ctrl+w+n, ctrl+w+v
• Move Between Screens ctrl+w.
• Global Settings Edit /etc/vimrc
• View the contents without editing vim -R /etc/passwd
Other Editors
• Nano nano nf2
• Gedit gedit file
-------------------------------------------------------------------------------------------------------------------------------------
www.abdelwahed.me
RHCSA Rapid Track | Quick Guide
---------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------
www.abdelwahed.me
RHCSA Rapid Track | Quick Guide
---------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------
www.abdelwahed.me
RHCSA Rapid Track | Quick Guide
---------------------------------------------------------------------------------------------------------------------------------------
o pkill -KILL -u user Sends the KILL signal to all processes owned by the user named "user",
forcefully terminating them.
o killall sshd Sends the TERM signal to all processes named "sshd", asking them to terminate
gracefully.
Monitoring using top and htop
• top A monitoring tool that monitors active processes in real time, sorting them based on processor
utilization. Can be customized with various keys
• f Add fields like PPID; z Color results; h More help.
• k Kill process; i Show only active processes; r Renice; q Quit.
• 1 Displays detailed information for each CPU.
• dnf install htop Installs htop (epel must be installed first).
Setting Process Priority with nice
• Commands
• nice -n 5 dd if=/dev/zero of=/dev/null & This command starts a dd process with a nice value
of 5, meaning it has a lower priority than the default processes.
• nice -n -5 dd if=/dev/zero of=/dev/null & This starts the same dd process, but this time with
a nice value of -5, giving it a higher priority.
• renice -n 10 -p 14721 This command is used to change the nice value of a running process. In this
case, it changes the nice value of the process with the PID (Process ID) 14721 to 10.
-------------------------------------------------------------------------------------------------------------------------------------
www.abdelwahed.me
RHCSA Rapid Track | Quick Guide
---------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------
www.abdelwahed.me
RHCSA Rapid Track | Quick Guide
---------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------
www.abdelwahed.me
RHCSA Rapid Track | Quick Guide
---------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------
www.abdelwahed.me
RHCSA Rapid Track | Quick Guide
---------------------------------------------------------------------------------------------------------------------------------------
Persisting journal:
Default Storage Behavior
o By default, systemd-journald uses volatile storage (logs stored in memory and lost on reboot)
unless /var/log/journal exists.
o Enabling Persistent Storage
mkdir -p /var/log/journal
Edit /etc/systemd/journald.conf and set Storage=persistent
systemctl restart systemd-journald.service
-------------------------------------------------------------------------------------------------------------------------------------
www.abdelwahed.me
RHCSA Rapid Track | Quick Guide
---------------------------------------------------------------------------------------------------------------------------------------
Scheduling jobs
Using crontab to Schedule Recurring Tasks
• Understanding crond Service Behavior
o The crond daemon reads its configuration every minute and schedules jobs for the next minute.
Allow at least a 3-minute margin between configuration and execution for optimal results.
• Installing and Starting cron
o Install the cronie package dnf install cronie
o Start the crond service systemctl start crond.service
• Viewing Log Messages
o Monitor log messages tail -f /var/log/messages
• Editing Cron Jobs
o System-wide cron jobs:Edit the main cron configuration vim /etc/crontab (including user)
o * * * * * root rm -rf /tmp/testdir/*
o 17 * * * * * ahmed rm -rf /home/ahmed/Desktop/*
o User-specific cron jobs: Edit user's cron jobs crontab -e
• Cron Job Format
o Example of job definition
* * * * * user-name command to be executed
o Fields represent minute, hour, day of month, month, day of week.
• Common Cron Job Examples
o 0,10,20,30,40,50 17-20 15 Jun,Jul,Aug * root /usr/local/bin/my-script.sh
This job runs on minutes 0, 10, 20, 30, 40, and 50 past the hour, from 5 PM to 8 PM, on the 15th day
of June, July, and August.
o 0 5,17 * * * bash /cron/batch This job runs at 5 AM and 5 PM daily.
o 3 12 * * sun /bin/systemctl stop atd.service This job runs at 12:03 PM every
sunday.
o * * * * * bash /cron/batch This job runs every minute.
o */10 * * * * /scripts/monitor.sh This job runs every 10 minutes.
o 0 17 * * sun,fri /script/script.sh This job runs at 5 PM on Sundays and Fridays.
• Managing Cron Jobs
o Remove cron job crontab -r
o List user's cron jobs crontab -l
• System-wide Cron Jobs
o Use /etc/cron.d for system-wide cron job configurations.
o System-wide scripts run from directories like /etc/cron.hourly, /etc/cron.daily, etc.
• Running Multiple Tasks in One Cron
o Use semicolons to run multiple tasks in a single cron entry.
• User-specific Cron Management
o Manage cron jobs for specific users
▪ Edit user's cron jobs crontab -e -u username
▪ List user's cron jobs crontab -l -u username
▪ Remove user's cron jobs crontab -r -u username
• Directory for System-wide Cron Jobs
o /etc/cron.d Store system-wide cron job configurations.
-------------------------------------------------------------------------------------------------------------------------------------
www.abdelwahed.me
RHCSA Rapid Track | Quick Guide
---------------------------------------------------------------------------------------------------------------------------------------
o /etc/cron.hourly, /etc/cron.daily, etc. Executed automatically by the cron daemon on
an hourly basis.
• Executing Scripts in a Directory
o Test cron job execution for a directory run-parts --test /etc/cron.hourly
o Execute all scripts in a directory nice run-parts /etc/cron.hourly
-------------------------------------------------------------------------------------------------------------------------------------
www.abdelwahed.me
RHCSA Rapid Track | Quick Guide
---------------------------------------------------------------------------------------------------------------------------------------
1. Creating Partitions
• fdisk -l /dev/sdb (List all partitions for a block)
• fdisk /dev/sdb (Create partition table with interactive options)
• partprobe /dev/sdb (Inform kernel of partition table changes)
• dd if=/dev/zero of=/dev/sdb count=1 bs=512 (Delete partitioning)
2. Adding File System and Labeling
File System Considerations
• ext4 Max file size of 2 TB.
• XFS Handles larger files, up to 8 EB.
o mkfs.xfs -L Data /dev/sdb2 (Create XFS filesystem with label)
o xfs_admin -L "mydata" /dev/sdc1 (Label unmounted XFS filesystem)
o xfs_admin -lu /dev/sdb1 (Show filesystem label and uuid)
o dumpe2fs /dev/sdb1 | less (Display filesystem metadata)
o Xfs_info /dev/sdb2
3. Mounting File System to Directory
• mount or findmnt (Show all mounted filesystems)
-------------------------------------------------------------------------------------------------------------------------------------
www.abdelwahed.me
RHCSA Rapid Track | Quick Guide
---------------------------------------------------------------------------------------------------------------------------------------
• f. umount /data/sdbdata1
1. Installing LVM
o dnf install lvm2 Install LVM package.
o pvcreate /dev/sd{a,b,c} Create physical volumes.
2. Creating Volume Groups and LV using GB
o vgcreate vg1 /dev/sd{a,b,c} Create a volume group.
o lvcreate -n lv1 -L 2G vg1 Create a 2GB logical volume.
o lvcreate -n lv2 -l 100%FREE vg1 Use remaining space for another logical volume.
o mkfs.xfs -L lvdata /dev/vg1/lv1 Format logical volume.
3. Creating an LV using PE
o vgdisplay vg0 | grep "PE Size" Determine the PE Size
o 40GB = 40 * 1024 MB = 40960 MB Convert the desired LV size to MB
o lvcreate -l 5000 -n lvdata vg0 Create the Logical Volume using PEs
4. Mounting and Using LVM
o mkdir /lvm1 Create a mount point.
o Add entry in /etc/fstab lvdata /mnt/lvm xfs defaults 0 0.
o mount -a Mount all filesystems in fstab.
o Test LVM Copy data to /mnt/lvm.
5. Resizing Logical Volumes
o vgextend vg1 /dev/sdd Extend volume group.
o lvextend -L +50G -r /dev/vg1/lv1 Extend logical volume (add 50G to the current size)
o lvextend -L 50G -r /dev/vg1/lv1 Extend logical volume (change the current size to 50G)
o xfs_growfs /mnt/lvm/ grow filesystem in case you not use -r option.
6. Remove LVM
o lvremove /dev/lvmraid/lvm1 Remove logical volume.
o vgremove lvmraid Remove volume group.
-------------------------------------------------------------------------------------------------------------------------------------
www.abdelwahed.me
RHCSA Rapid Track | Quick Guide
---------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------
www.abdelwahed.me
RHCSA Rapid Track | Quick Guide
---------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------
www.abdelwahed.me
RHCSA Rapid Track | Quick Guide
---------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------
www.abdelwahed.me
RHCSA Rapid Track | Quick Guide
---------------------------------------------------------------------------------------------------------------------------------------
• Check Website Accessibility curl www.google.com If it returns the website's content, the site is
accessible.
• Download Using curl curl -O www.site/filename This can replace wget if it's not supported in your
system.
• Ping a Website ping www.google.com For a limited number of pings, use
ping -c 5 www.google.com; Ping ping6 www.google.com
-------------------------------------------------------------------------------------------------------------------------------------
www.abdelwahed.me
RHCSA Rapid Track | Quick Guide
---------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------
www.abdelwahed.me
RHCSA Rapid Track | Quick Guide
---------------------------------------------------------------------------------------------------------------------------------------
Container
Basic Concept of Containers
• Containers are a way to package applications and their dependencies into isolated, self-contained
environments. This allows applications to run consistently across different systems without conflicts.
• Lightweight: Unlike virtual machines, which contain a full operating system, containers only package the
application and its dependencies. They share the host system's OS kernel, making them much smaller and
faster to start.
• Portable: Containers can run the same way across various environments (developer laptops, data centers,
cloud) because they package everything the application needs. This makes it easy to move applications
between development, testing, and production without changes.
• Isolated: Each container runs in its own environment, isolated from other containers and the host system.
This protects applications from interfering with each other, enhances security, and makes it easier to
manage dependencies.
• Daemonless:
o Traditional container engines like Docker use a background service (daemon) to manage containers.
The Docker daemon runs with elevated privileges and handles tasks like starting, stopping, and
monitoring containers.
o Podman, on the other hand, is daemonless. It doesn’t rely on a background service; instead, each
command directly manages containers. This design makes Podman simpler and avoids the single
point of failure associated with a daemon.
o Most container engines require root privileges to create and manage containers, which can
introduce security risks if a container is compromised.
o Podman allows containers to run without root access (rootless mode), making it more secure. In
rootless mode, users can create and manage containers within their own user namespace, isolating
them from the host system.
o This feature is especially valuable for multi-user environments where unprivileged users need to run
containers safely without requiring administrative rights.
-------------------------------------------------------------------------------------------------------------------------------------
www.abdelwahed.me
RHCSA Rapid Track | Quick Guide
---------------------------------------------------------------------------------------------------------------------------------------
Step-by-Step Lab: Running a Container
1. Install Podman
• Start by updating the system and installing Podman:
sudo dnf update -y
sudo dnf install -y podman
• Verify the installation to ensure Podman was installed correctly:
podman --version
2. Pull the Alpine Image
• Download the Alpine Linux image to use as a lightweight base:
podman pull alpine
3. Run the Container with Custom CPU and Memory Limits
• Start the container with specific CPU and memory limitations. In this example, we limit the container to use
1.5 CPU cores and 512 MB of RAM.
podman run -d --name limited_container \
--cpus=1.5 \
--memory=512m \
alpine sleep infinity
• Explanation:
o --cpus=1.5: Restricts the container to using a maximum of 1.5 CPU cores.
o --memory=512m: Limits the container’s memory usage to 512 MB.
o alpine sleep infinity: Runs the Alpine container with a command to keep it running
indefinitely.
4. Verify the Container's Configuration
• Check Container Status:
o List running containers to confirm that your container is up and running:
podman ps
• Inspect Resource Limits:
o Use the inspect command to check that the CPU and memory limits are applied:
podman inspect limited_container | grep -E 'Cpu|Memory'
• Monitor Resource Usage:
o View real-time resource usage with podman stats:
podman stats limited_container
5. Interact with the Running Container
• You can execute commands within the running container to verify its environment and observe resource
usage:
podman exec -it limited_container sh
• Once inside the container, you can run simple commands like:
top # To view CPU and memory usage within the container
exit # To leave the container shell
uname -a # Displays kernel and system information
cat /proc/meminfo # Shows detailed memory info
-------------------------------------------------------------------------------------------------------------------------------------
www.abdelwahed.me
RHCSA Rapid Track | Quick Guide
---------------------------------------------------------------------------------------------------------------------------------------
cat /proc/cpuinfo # Shows CPU details
yes > /dev/null &
pkill yes
To stop and remove an Alpine container in Podman (or Docker), follow these steps:
Step 1: List Running Containers
• First, check the list of running containers to find the container name or ID of your Alpine container:
podman ps
• If the container is not currently running but was created, you can list all containers (including stopped ones)
with:
podman ps -a
Step 2: Stop the Container
• Use the container name or ID from the previous step to stop the Alpine container:
podman stop <container_name_or_id>
• Example:
podman stop my_alpine_container
Step 3: Remove the Container
• After stopping it, remove the Alpine container using its name or ID:
podman rm <container_name_or_id>
• Example:
podman rm my_alpine_container
-------------------------------------------------------------------------------------------------------------------------------------
www.abdelwahed.me