RHEL 9 Admin

CH01 – Install RHEL 9

RHEL 9 Installation Process

  • ISO: Download from Red Hat Customer Portal
  • Boot Media: Create USB using dd or Rufus
  • Boot: Boot the system from the ISO/USB
  • Language: Select language and keyboard
  • Installation Destination: Manual or Automatic Partitioning
  • Network: Configure network and hostname
  • Software Selection: Server with GUI or Minimal Install
  • User Setup: Set root password and create a user
  • Install: Begin installation
  • Finish: Reboot and log in

Post Installation

  • Update System: dnf update -y
  • Register Subscription: subscription-manager register
  • Attach Subscription: subscription-manager attach --auto
CH02 – Access Command Line

Terminals & Shells

  • Terminal Types: GNOME Terminal, TTY (Ctrl + Alt + F1–F6)
  • Common Shells: bash, zsh

Check Current User

  • whoami → displays the current logged-in username
  • id → shows user ID (UID), group ID (GID), and groups

Check Current Directory

  • pwd → print working directory (current directory path)

User Types

  • Normal User → standard user without root privileges
  • Superuser / Root → has full administrative privileges; prompt often shows as #
  • Normal user → prompt often shows as $

Switching Users

  • su - → switch to root user (superuser) with full login environment
  • su username → switch to another user
  • exit → return to previous user session

Shortcuts

  • Tab → Auto-complete command or file name
  • Up / Down Arrow → Browse command history

User & Session Management

  • id → show current user ID and groups
  • su - → switch to root user with login environment
  • exit → exit current shell or user session
  • reboot → reboot the system
  • hostname → show or set the system hostname

Navigation

  • cd . → stay in current directory
  • cd .. → move up one directory
  • cd /absolute/path → move to absolute path
  • cd relative/path → move to relative path
  • pwd → print current directory
CH03 – Managing Files

Listing Files

  • ls -l → list files with details
  • ll → shorthand alias for ls -l
  • ls -a → list all files including hidden
  • ls -lh → human-readable sizes
  • ls -R → recursive listing
  • ls -r → reverse order
  • ls -li → inode number with listing
  • ls -lahR → all options combined
  • ln → create hard link
  • ln -s → create symbolic link

File Operations

  • cp source dest → copy file
  • cp -r source dest → copy directory recursively
  • mv old new → move or rename file/directory
  • rm file → delete file
  • mkdir dir → create directory
  • rmdir dir → remove empty directory
  • rm -r dir → remove directory recursively

Viewing Files

  • cat file → display file contents
  • less file → scrollable view
  • more file → paginate content
  • head file → first 10 lines by default
  • head -n N file → first N lines
  • tail file → last 10 lines by default
  • tail -n N file → last N lines
CH04 – Getting Help

Documentation & Logs

  • man command → open the manual page for a command
  • command --help → show brief help and options for a command
  • man -k keyword → search manuals by keyword
  • info command → detailed info pages, often more structured than man
  • whatis command → one-line description of a command
  • journalctl -xe → view system logs and recent errors (requires sudo for full access)
CH05 – Text Files

Creating Files

  • touch file.txt → create empty file or update timestamp
  • echo "text" > file.txt → create file with text (overwrite)
  • echo "text" >> file.txt → append text to file
  • cat > file.txt → create file and type content interactively
  • printf "text\n" > file.txt → create file with formatted text

Editing Files

  • nano file.txt → simple terminal editor
  • vi file.txt → powerful terminal editor
    • i → insert mode
    • :w → save
    • :q → quit
    • :wq → save & quit
    • :q! → quit without saving
  • vim file.txt → improved version of vi
  • gedit file.txt → graphical text editor (GUI)
  • sed -i 's/old/new/g' file.txt → replace text inline
  • awk '{print $1}' file.txt → extract fields from text

Viewing Files

  • cat file.txt → display entire content
  • less file.txt → scrollable view
  • more file.txt → paginate content
  • head file.txt → first 10 lines
  • head -n N file.txt → first N lines
  • tail file.txt → last 10 lines
  • tail -n N file.txt → last N lines
  • wc file.txt → count lines, words, and characters
  • grep "pattern" file.txt → search for pattern in file
  • diff file1.txt file2.txt → show differences between files
  • cmp file1.txt file2.txt → compare files byte by byte

Grep

  • grep "text" file → search for text inside a file
  • grep -i "text" file → case‑insensitive search
  • grep -r "text" /path → search recursively in directories
  • grep -v "text" file → show lines that do NOT match
  • grep -n "text" file → show line numbers
  • grep -l "text" * → show only filenames with matches
CH06 – Local Users & Groups

User Management

  • useradd username → create new user
  • useradd -m username → create user with home directory
  • useradd -u 1001 username → create user with specific UID
  • useradd -g groupname username → set primary group
  • useradd -G group1,group2 username → add to multiple groups
  • useradd -s /bin/bash username → set default shell
  • useradd -c "Full Name" username → add user description
  • usermod -aG groupname username → add user to group
  • usermod -u 2001 username → change user UID
  • usermod -g groupname username → change primary group
  • usermod -d /home/newdir username → change home directory
  • usermod -s /bin/zsh username → change default shell
  • usermod -L username → lock user account
  • usermod -U username → unlock user account
  • passwd username → set or change password
  • passwd -l username → lock user password
  • passwd -u username → unlock user password
  • passwd -e username → force password change at next login
  • userdel username → delete user
  • userdel -r username → delete user and home directory
  • who → show currently logged in users
  • whoami → show current user
  • id username → show user ID, group ID, and groups
  • groups username → show groups of user
  • getent passwd username → get user info from passwd database
  • cat /etc/passwd → list all users

User Options Breakdown

  • -u → user ID (UID)
  • -g → primary group
  • -G → supplementary groups
  • -a → append (used with -G)
  • -c → comment / description
  • -d → home directory
  • -m → create home directory
  • -s → login shell
  • -U → create group with same name
  • -L → lock account

Group Management

  • groupadd groupname → create new group
  • groupadd -g 1001 groupname → create group with specific GID
  • groupmod -n newname oldname → rename group
  • groupmod -g 2001 groupname → change group GID
  • groupdel groupname → delete group
  • gpasswd -a username groupname → add user to group
  • gpasswd -d username groupname → remove user from group
  • groups username → list groups for a user
  • id username → show user groups info
  • getent group groupname → get group info from database
  • cat /etc/group → list all groups
CH07 – Controlling Access

Basic Permissions

  • ls -l → view file permissions
  • chmod 755 file → set permissions (rwxr-xr-x)
  • chmod u+x file → add execute for owner
  • chmod g-w file → remove write for group
  • chmod o=r file → set others to read-only
  • chown user:group file → change owner and group
  • chown user file → change owner only
  • chgrp group file → change group only
  • stat file → detailed file info including permissions

Special Permissions (SUID, SGID, Sticky Bit)

SUID (Set User ID)

  • Symbol: s in the owner's execute position (rws)
  • Effect: Executes the file with the file owner’s permissions, not the user running it
  • Add SUID: chmod u+s <file>
  • Remove SUID: chmod u-s <file>
  • Example: chmod 4755 /usr/bin/passwd

SGID (Set Group ID)

  • Symbol: s in the group's execute position (rws)
  • Effect on files: Executes with the file's group permissions
  • Effect on directories: New files inside inherit the directory's group
  • Add SGID: chmod g+s <file_or_directory>
  • Remove SGID: chmod g-s <file_or_directory>
  • Example: chmod 2755 /shared/folder

Sticky Bit

  • Symbol: t in the others’ execute position (rwt)
  • Effect: Only the owner of the file or root can delete/rename files in the directory
  • Add Sticky Bit: chmod +t <directory>
  • Remove Sticky Bit: chmod -t <directory>
  • Common use: /tmp directory
  • Example: chmod 1777 /tmp
CH08 – Managing Processes

View Processes

  • ps aux → show all running processes with details
  • ps -ef → alternative full-format process listing
  • top → interactive process viewer
  • htop → enhanced interactive process viewer (colorful)
  • pidof process_name → get PID(s) of a process
  • pgrep process_name → search for process by name

Manage Processes

  • kill PID → terminate process gracefully
  • kill -9 PID → force kill process
  • pkill process_name → kill process by name
  • killall process_name → kill all instances of a process
  • renice +10 PID → lower process priority
  • renice -10 PID → increase process priority
  • nice -n 10 command → start command with specific priority

Jobs & Background Processes

  • jobs → list background jobs in current shell
  • bg %job_number → resume job in background
  • fg %job_number → bring job to foreground
  • & → append to command to run in background (e.g., `sleep 100 &`)
  • disown %job_number → remove job from shell job table

System-Wide Monitoring

  • uptime → show system uptime and load averages
  • vmstat → report virtual memory, CPU, and IO stats
  • iostat → CPU and disk IO statistics
  • free -h → show memory usage
  • watch command → run a command periodically and display output
CH09 – Services & Daemons

Systemd Service Management

  • systemctl start service → start a service immediately
  • systemctl stop service → stop a running service
  • systemctl restart service → restart a service
  • systemctl reload service → reload service configuration without restarting
  • systemctl enable service → enable service to start at boot
  • systemctl disable service → disable service from starting at boot
  • systemctl status service → show current status and logs of service
  • systemctl is-active service → check if service is running
  • systemctl is-enabled service → check if service is enabled at boot
  • systemctl mask service → prevent service from starting
  • systemctl unmask service → remove mask to allow starting

Listing Services

  • systemctl list-units --type=service → list active services
  • systemctl list-unit-files --type=service → list all service unit files with enable/disable status
  • systemctl list-dependencies service → show service dependencies
  • systemctl cat service → show unit file configuration
  • systemctl show service → detailed properties of service

Logs

  • journalctl -u service → view logs for a specific service
  • journalctl -xe → view system-wide logs with details
  • journalctl -f → follow log output live
CH10 – Securing SSH

Starting & Enabling SSH Service

  • systemctl start sshd → start SSH service immediately
  • systemctl enable sshd → enable SSH to start at boot
  • systemctl restart sshd → restart SSH service after config changes
  • systemctl status sshd → check SSH service status

SSH Configuration

  • Config file: /etc/ssh/sshd_config
  • Port 2222 → change SSH port for security
  • PermitRootLogin no → disable root login via SSH
  • PasswordAuthentication no → disable password login for key-based auth
  • AllowUsers user1 user2 → restrict which users can SSH

Connecting & secure Copying Files

  • ssh user@host → connect to remote server
  • scp file user@host:/path → copy file to remote server
  • scp user@host:/path/file . → copy file from remote server
  • rsync -avz file user@host:/path → efficient file transfer

Key-Based Authentication

  • ssh-keygen → generate SSH key pair
  • ssh-copy-id user@host → copy public key to remote server
  • ssh -i ~/.ssh/id_rsa user@host → connect using specific private key
  • ssh-agent bash → start SSH agent
  • ssh-add ~/.ssh/id_rsa → add private key to agent

Monitoring & Security

  • journalctl -u sshd → view SSH logs
  • ss -tuln | grep 22 → check listening SSH port
  • fail2ban-client status sshd → monitor failed login attempts (if fail2ban installed)
CH11 – Analyzing Logs

Viewing Logs

  • journalctl → show all systemd logs
  • journalctl -xe → show recent errors with details
  • journalctl -u service → show logs for a specific service
  • journalctl -b → show logs since last boot
  • journalctl -f → follow logs live
  • journalctl --since "YYYY-MM-DD HH:MM" → logs from specific time
  • journalctl -p err → show only errors

Rotating Logs

  • logrotate → automatic log rotation tool
  • Config files: /etc/logrotate.conf and /etc/logrotate.d/
  • logrotate -d /etc/logrotate.conf → debug log rotation without executing
  • logrotate -f /etc/logrotate.conf → force rotate logs
  • /var/log/*.log → commonly rotated log files

Monitoring Logs in Real-Time

  • tail -f /var/log/messages → follow log file live
  • tail -n 50 -f /var/log/messages → last 50 lines and follow
  • less +F /var/log/syslog → follow log file interactively
  • grep "error" /var/log/messages → filter log entries by keyword
  • watch tail -n 20 /var/log/messages → update last 20 lines every 2 seconds
CH12 – Managing Networking

Show Network Information

  • ip addr → display IP addresses and interfaces
  • ip link → show network interfaces and status
  • ip route → show routing table
  • ip route add default via 192.168.1.1 → add default gateway
  • ip route del default → delete default route
  • ethtool eth0 → detailed info for a network interface

Configure Network Interface

  • nmcli con add type ethernet con-name eth0 ifname eth0 → create Ethernet connection
  • nmcli con up eth0 → bring up interface
  • nmcli con down eth0 → bring interface down
  • nmcli con show → show network connections
  • nmcli con modify eth0 ipv4.addresses 192.168.1.10/24 → set static IP
  • nmcli con modify eth0 ipv4.gateway 192.168.1.1 → set gateway
  • nmcli con modify eth0 ipv4.dns "8.8.8.8 8.8.4.4" → set DNS servers
  • nmcli con reload → reload connections
  • nmcli device status → list all devices and their state
  • nmcli connection show → show configured connections
  • nmtui → open text-based network manager UI

Socket Statistics (ss)

  • ss -tulap → show all listening ports with processes
  • ss -n → show connections without resolving names
  • ss -t → show TCP connections
  • ss -u → show UDP connections
  • ss -l → show listening sockets
  • ss -a → show all sockets
  • ss -p → show process using socket

Routing Table

  • netstat -nr → show routing table (numeric format)

Network Path Tracing

  • traceroute 8.8.8.8 → trace path to destination
  • tracepath 8.8.8.8 → trace network path (no root needed)

Check Connectivity

  • ping 8.8.8.8 → check connectivity to IP
  • ping google.com → check DNS resolution
  • traceroute 8.8.8.8 → trace path to host
  • curl -I http://example.com → check HTTP response
  • dig google.com → query DNS records
  • nslookup google.com → alternative DNS query

DNS Configuration

  • Config file: /etc/resolv.conf → define nameservers
  • nmcli dev show eth0 | grep DNS → show DNS used by interface
CH13 – Archiving Files

Compressing & Archiving

  • tar -cvf archive.tar dir/ → create tar archive of directory
  • tar -xvf archive.tar → extract tar archive
  • tar -czvf archive.tar.gz dir/ → create gzip compressed tar
  • tar -xzvf archive.tar.gz → extract gzip compressed tar
  • tar -cjvf archive.tar.bz2 dir/ → create bzip2 compressed tar
  • tar -xjvf archive.tar.bz2 → extract bzip2 compressed tar
  • gzip file → compress file using gzip
  • gunzip file.gz → decompress gzip file
  • bzip2 file → compress file using bzip2
  • bunzip2 file.bz2 → decompress bzip2 file
  • zip archive.zip file1 file2 → create zip archive
  • unzip archive.zip → extract zip archive
  • 7z a archive.7z dir/ → create 7zip archive (if p7zip installed)
  • 7z x archive.7z → extract 7zip archive
  • tar -tvf archive.tar → list contents of tar archive

Transferring Files

  • scp file user@host:/path → copy file to remote server
  • scp -r dir user@host:/path → copy directory recursively
  • rsync -avz source user@host:/dest → efficient sync and transfer
  • rsync -avz --delete source user@host:/dest → sync and delete files not in source
  • rsync -avz -P source user@host:/dest → show progress and allow resume
  • ftp host → transfer files via FTP
  • sftp user@host → secure file transfer over SSH
  • scp user@host:/path/file . → copy file from remote server to local
CH14 – Software Packages

Basic Package Management

  • dnf install package → install a new package
  • dnf remove package → remove/uninstall a package
  • dnf update -y → update all packages automatically
  • dnf upgrade package → update specific package
  • dnf list installed → list all installed packages
  • dnf list available → list available packages
  • dnf search keyword → search for packages by keyword
  • dnf info package → detailed info about a package

Group and Bulk Operations

  • dnf groupinstall "Server with GUI" → install a package group
  • dnf groupremove "Server with GUI" → remove a package group
  • dnf check-update → list packages with available updates
  • dnf autoremove → remove unused dependencies
  • dnf clean all → clean cached metadata and packages
  • dnf repolist → list enabled repositories
  • dnf repoinfo → detailed info about repositories

Advanced Operations

  • dnf downgrade package → revert package to older version
  • dnf history → view transaction history
  • dnf history undo transaction_ID → undo a previous transaction
  • dnf config-manager --add-repo URL → add custom repository
  • dnf config-manager --disable repo → disable a repository
  • rpm -qa | grep package → check if package installed using rpm

YUM Package Management (RHEL 7 and older, backward-compatible)

  • yum install package → install package
  • yum remove package → remove package
  • yum update -y → update all packages
  • yum upgrade package → update specific package
  • yum list installed → list installed packages
  • yum list available → list available packages
  • yum search keyword → search packages
  • yum info package → show package info
  • yum groupinstall "Server with GUI" → install package group
  • yum groupremove "Server with GUI" → remove package group
  • yum clean all → clear metadata and cache

RPM Package Management (Low-level, works without network)

  • rpm -ivh package.rpm → install RPM package
  • rpm -Uvh package.rpm → upgrade or install package
  • rpm -e package → remove installed package
  • rpm -qa → list all installed packages
  • rpm -qi package → detailed info about installed package
  • rpm -ql package → list files installed by package
  • rpm -qc package → list configuration files from package
  • rpm -qf /path/to/file → find which package owns a file
CH15 – Access File Systems

Listing Disks & Partitions

  • lsblk → list block devices and partitions
  • blkid → show partition UUIDs and file system types
  • fdisk -l → list partition tables
  • parted -l → show disk partitions and sizes
  • df -h → show mounted disks with usage in human-readable format

Mounting & Unmounting Filesystems

  • mount /dev/sda1 /mnt → mount filesystem
  • mount -o ro /dev/sda1 /mnt → mount read-only
  • mount -t ext4 /dev/sda1 /mnt → specify filesystem type
  • umount /mnt → unmount filesystem
  • umount -l /mnt → lazy unmount (detach immediately)
  • mount | grep /mnt → check if filesystem is mounted

Disk & Folder Usage

  • df -h → disk usage per mounted filesystem
  • df -i → inode usage per filesystem
  • du -sh /path → total size of folder
  • du -h --max-depth=1 /path → show sizes of subdirectories

Filesystem Maintenance

  • fsck /dev/sda1 → check and repair filesystem
  • mkfs.ext4 /dev/sda1 → create ext4 filesystem
  • mkfs.xfs /dev/sda1 → create XFS filesystem
  • tune2fs -l /dev/sda1 → show filesystem info
  • resize2fs /dev/sda1 → resize ext2/3/4 filesystem
  • e2fsck /dev/sda1 → ext2/3/4 filesystem check

Mounting Options & Persistence

  • /etc/fstab → configure filesystems to mount at boot
  • UUID=$(blkid -s UUID -o value /dev/sda1) → get filesystem UUID for fstab
  • mount -o defaults,noatime /dev/sda1 /mnt → mount with options
CH01 – CMD Productivity

Bash Magic

  • Ctrl + A → move cursor to start of the line
  • Ctrl + E → move cursor to end of the line
  • Ctrl + R → reverse search through command history
  • !$ → reference the last argument of previous command
  • $(command) → command substitution; use output of a command as input
  • !! → repeat the last command
  • Alt + . → insert last argument of previous command (similar to !$)
  • \ → escape special characters

Examples

  • echo "Today is $(date)" → prints: Today is current_date
  • cp file1 !$/destination/ → uses last argument from previous command as source

Shebang

  • #!/bin/bash → specify bash interpreter for script
  • which bash → show path of bash interpreter

Basic Commands

  • mount → mount a filesystem
  • umount → unmount filesystem
  • lsof → list open files
  • echo $PATH → display executable search paths
  • echo $? → show exit status of last command

For Loop

  • for var in list → iterate through list values
  • do → start loop block
  • done → end loop block

Example

  • for i in 1 2 3; do echo $i; done → prints numbers 1 to 3

While Loop

  • while [ condition ] → run loop while condition is true
  • do → start loop block
  • done → end loop block

Until Loop

  • until [ condition ] → run loop until condition becomes true
  • do → start loop block
  • done → end loop block

If Statement

  • if [ condition ] → start condition block
  • then → execute commands if condition is true
  • elif → else if condition
  • else → default command
  • fi → end if statement

Numeric Comparison Operators

  • -eq → equal
  • -ne → not equal
  • -gt → greater than
  • -ge → greater or equal
  • -lt → less than
  • -le → less or equal

String Comparison

  • = → equal
  • != → not equal
CH02 – Scheduling Tasks

Crontab (Recurring Jobs)

  • crontab -e → edit current user's crontab
  • crontab -l → list current user's crontab entries
  • crontab -r → remove current user's crontab
  • crontab -u <username> → edit crontab for specific user
  • Format: Min Hr Day Mon Wkday command → schedule recurring jobs
    • Min: 0-59
    • Hr: 0-23
    • Day: 1-31
    • Mon: 1-12
    • Wkday: 0-7 (0 or 7 = Sunday)
  • Special strings:
    • @reboot → run command at system startup
    • @daily / @weekly / @monthly → run once per day/week/month

At (One-Time Jobs)

  • at 14:00 → schedule command to run at 2 PM
  • at now + 5 minutes → run command 5 minutes from now
  • atq → list pending at jobs
  • at -l → list pending at jobs for current user
  • at -c JOB_ID → display the commands scheduled for a specific job
  • at -r JOB_ID → remove a scheduled job (same as atrm)
  • atrm JOB_ID → remove scheduled at job

At Job Files & Permissions

  • /var/spool/at → directory where pending at jobs are stored
  • /etc/at.allow → users allowed to schedule at jobs
  • /etc/at.deny → users denied from scheduling at jobs

System Timers

  • systemctl list-timers → list active systemd timers

Monitoring Commands

  • watch <command> → run a command repeatedly and show output (useful for monitoring jobs)
CH03 – Tuning Performance

System Monitoring

  • sar -r → display memory usage statistics
  • ps lax → show detailed process list in BSD format
  • ps axo pid,comm,ni → display processes with nice (priority) values

Process Priority

  • nice -n 10 command → start process with lower priority
  • renice 5 -p PID → change priority of running process
  • -20 to 19 → priority range (lower number = higher priority)

Systemd

  • systemctl daemon-reload → reload systemd configuration after editing service files

Tuned Performance Profiles

  • tuned-adm active → show current active profile
  • tuned-adm recommend → show recommended profile for system
  • tuned-adm profile profile_name → apply performance profile
  • tuned-adm off → disable tuned service
  • tuned-adm list → list available profiles
  • /usr/lib/tuned → directory containing tuned profiles

Cockpit Web Console

  • systemctl enable --now cockpit.socket → enable cockpit service
  • Port 9090 → cockpit web interface port
  • https://server-ip:9090 → access cockpit from browser

CPU & Processes

  • top / htop → live CPU and memory usage
  • ps aux --sort=-%cpu → list processes sorted by CPU usage
  • nice -n 10 <command> → start a process with lower priority
  • renice -n 5 -p <pid> → change priority of a running process

Memory & Swap

  • free -h → show memory usage
  • vmstat 1 → memory, CPU, and I/O statistics
  • swapon -s → display swap usage
  • sysctl vm.swappiness=10 → adjust swap usage behavior

I/O & Disk

  • iostat -x → detailed disk I/O statistics
  • iotop → live disk I/O monitoring
  • tune2fs -l /dev/sda1 → view filesystem tuning parameters

Kernel & System Tuning

  • sysctl -a → list all kernel parameters
  • sysctl -w net.ipv4.ip_forward=1 → enable IP forwarding
  • dstat / sar → advanced system monitoring
CH04 – Advanced ACLs

ACLs

  • getfacl <file> → view ACL entries
  • getfacl -R /path → recursively list ACLs
  • setfacl -m u:<user>:rwx <file> → add/modify ACL for user
  • setfacl -m g:<group>:rx <file> → add/modify ACL for group
  • setfacl -m o::r <file> → set permissions for others via ACL
  • setfacl -x u:<user> <file> → remove ACL for user
  • setfacl -b <file> → remove all ACL entries
  • setfacl -k <dir> → remove default ACLs only
  • setfacl -d -m u:<user>:rw <dir> → set default ACL for new files in directory
  • setfacl -m d:u:<user>:rw- <dir> → another way to set default ACL
  • setfacl -m m::r <file> → modify ACL mask permissions
  • setfacl -n → do not recalculate effective rights mask
  • cp -p file1 file2 → copy file with permissions & timestamps
  • getfacl file1 | setfacl --set-file=- file2 → copy ACLs between files
CH05 – SELinux Security

Processes

  • ps axz → show all running processes with threads
  • ps -zc sshd → show process info for sshd by command name

Modes

  • getenforce → show current mode (Enforcing / Permissive / Disabled)
  • setenforce 0 → switch to Permissive mode temporarily
  • setenforce 1 → switch to Enforcing mode

Contexts

  • ls -Z → show SELinux security context
  • chcon -t httpd_sys_content_t <file> → change SELinux context type
  • restorecon -Rv /var/www/html → restore default SELinux context

Ports & SELinux

  • semanage port -a -t -l ssh_port_t -p tcp 22 → add a port to SELinux type
  • semanage port -a -t ssh_port_t -p tcp 22 → add port 22 to SELinux type ssh_port_t
  • semanage port -a → add a new port mapping
  • semanage port -t <type> → specify the SELinux type for a port
  • semanage port -l → list all SELinux port mappings
  • semanage port -l | grep 9999 → list SELinux port mappings and filter for port 9999

Booleans

  • getsebool -a → list all SELinux booleans
  • setsebool -P httpd_enable_homedirs on → enable boolean permanently
  • audit2why -a → explain SELinux denials
  • audit2allow -a -M mymodule → create policy module to allow action
  • semanage boolean -l → list SELinux booleans with details

Audit & Logs

  • ausearch -m AVC -ts recent → search recent SELinux AVC denials

Networking & Cockpit

  • curl http://<host> → test HTTP connectivity
  • cockpit listen 9090 → start Cockpit web console on port 9090

SELinux Status

  • selinux → show SELinux status summary

Control Groups

  • cgl → list control groups (cgroups) for processes
CH06 – Basic Storage

Disks

  • lsblk -f → show block devices and filesystems
  • blkid → display device UUID
  • fdisk /dev/sda → MBR partitioning tool
  • parted /dev/sda → GPT partitioning tool
  • mkfs.ext4 /dev/sda1 → format partition with ext4 filesystem
  • mount /dev/sda1 /mnt → mount partition
  • mount -o ro /dev/sda1 /mnt → mount partition as read-only
  • /etc/fstab → configure persistent mounts
  • df -h → show disk usage
  • du -sh /path → show directory size
  • fsck /dev/sda1 → check and repair filesystem
CH07 – LVM (Logical Volumes)

Workflow

  • PV → Physical Volume
  • VG → Volume Group
  • LV → Logical Volume
  • pvcreate /dev/sdb → create Physical Volume (PV)
  • vgcreate vg_data /dev/sdb → create Volume Group (VG)
  • lvcreate -L 10G -n lv_data vg_data → create Logical Volume (LV)
  • lvextend -L +5G /dev/vg_data/lv_data → extend logical volume
  • lvreduce -L 5G /dev/vg_data/lv_data → reduce logical volume
  • lvcreate -L 2G -s -n snap_lv /dev/vg/lv_data → create snapshot
  • vgextend vg_data /dev/sdc → add PV to Volume Group
  • vgreduce vg_data /dev/sdb → remove PV from Volume Group
CH08 – Advanced Storage

RAID & VDO

  • mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc → create RAID 1 array
  • mdadm --detail /dev/md0 → show RAID details
  • cat /proc/mdstat → show RAID sync status

Stratis

  • stratis pool create mystorage /dev/sdb /dev/sdc → create Stratis storage pool
  • stratis filesystem create mystorage myfs → create filesystem in pool

VDO (Virtual Data Optimizer)

  • vdo create --name=myvdo --device=/dev/sdb --vdoLogicalSize=100G → create VDO volume
  • vdo status → show VDO status

Encryption (LUKS)

  • cryptsetup luksFormat /dev/sdb1 → encrypt partition
  • cryptsetup open /dev/sdb1 secret → open encrypted device
  • cryptsetup luksClose secret → close encrypted device
CH09 – Network Storage

NFS & CIFS

NFS

  • mount -t nfs server:/export /mnt → mount NFS share
  • mount -o vers=4,hard,intr server:/export /mnt → mount using NFSv4
  • showmount -e server → list exported NFS shares
  • autofs → automatically mount network shares

CIFS / SMB

  • mount -t cifs //server/share /mnt -o username=user,password=pass → mount SMB share
  • ,domain=corp,sec=ntlmssp → include domain and security options
CH10 – Boot Process

Targets

  • grub2-mkconfig -o /boot/grub2/grub.cfg → regenerate GRUB configuration
  • grub2-set-default 2 → set default boot entry
  • systemctl get-default → show current system target
  • systemctl set-default multi-user.target → change default target
  • journalctl -b → view boot logs
  • systemctl rescue or rd.break → rescue mode at boot

Root Password Reset

  • Reboot system → access GRUB menu
  • Press 'e' → edit the boot entry
  • Find line starting with "linux" → append rd.break
  • Press Ctrl + X → boot into emergency mode
  • mount -o remount,rw /sysroot → remount system as read/write
  • chroot /sysroot → change root to system
  • passwd → set new root password
  • touch /.autorelabel → relabel SELinux context
  • exit → exit chroot
  • reboot → restart system
CH11 – Network Security

Firewall

  • firewall-cmd --state → check firewall status
  • firewall-cmd --add-service=http --permanent → allow HTTP service
  • firewall-cmd --reload → reload firewall rules

Zones

  • firewall-cmd --get-active-zones → show active firewall zones
  • firewall-cmd --zone=public --add-port=8080/tcp --permanent → open port 8080

SSH

  • /etc/ssh/sshd_config → configure SSH (port, root login)
  • systemctl restart sshd → restart SSH service

Intrusion & Logging

  • fail2ban → block repeated login attempts
  • iptables -L -v → list firewall rules
CH12 – Installing RHEL

Installation Steps

  • 1. Boot ISO or PXE
  • 2. Select language & keyboard
  • 3. Configure network & hostname
  • 4. Partition disks (automatic or manual)
  • 5. Select software packages
  • 6. Set root password & create user
  • 7. Begin installation
  • Post-install

    • subscription-manager register → register system
    • subscription-manager attach --auto → attach subscription
    • dnf update -y → update system packages

    Package Management

    • dnf install package → install package
    • dnf remove package → remove package
    • dnf list installed → list installed packages
    • dnf groupinstall "Server with GUI" → install package group

    Kickstart Automation

    • ks.cfg → automated installation configuration
    • inst.ks=hd:LABEL=RHEL-ISO:/ks.cfg → boot parameter for Kickstart
Made with ❤️ by AbdElRahman