<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Babatunde on Medium]]></title>
        <description><![CDATA[Stories by Babatunde on Medium]]></description>
        <link>https://medium.com/@bamidelebabatundem?source=rss-99476dec8c94------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*JCnJCx24IhYl5ftAvZ1DuQ@2x.jpeg</url>
            <title>Stories by Babatunde on Medium</title>
            <link>https://medium.com/@bamidelebabatundem?source=rss-99476dec8c94------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 09:48:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bamidelebabatundem/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Automated RHEL System Monitoring with Bash, Systemd & Email Alerts]]></title>
            <link>https://medium.com/@bamidelebabatundem/automated-rhel-system-monitoring-with-bash-systemd-email-alerts-efae6df7a436?source=rss-99476dec8c94------2</link>
            <guid isPermaLink="false">https://medium.com/p/efae6df7a436</guid>
            <category><![CDATA[monitoring-system]]></category>
            <category><![CDATA[systemd]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[bash-scripting]]></category>
            <category><![CDATA[gmail]]></category>
            <dc:creator><![CDATA[Babatunde]]></dc:creator>
            <pubDate>Thu, 29 Oct 2026 14:14:03 GMT</pubDate>
            <atom:updated>2026-10-29T14:14:03.117Z</atom:updated>
            <content:encoded><![CDATA[<h3>Objectives</h3><ul><li>Monitor CPU, memory, and disk usage.</li><li>Automate log cleanup and system reporting.</li><li>Send monitoring reports via email</li><li>Schedule daily tasks for a stable, reliable RHEL environment.</li></ul><h3>1. Monitor System Resources</h3><p><strong>1. Check CPU &amp; Memory Usage</strong></p><pre>top</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7GHtfWlhYnjPlKM3x9dSog.png" /></figure><ul><li><strong>What it does:</strong> Shows live CPU, memory, and process usage.</li><li><strong>Why:</strong> Identify processes using high resources; helps prevent overloads.</li></ul><pre>free -h</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*WrzZPu4TjlyHFdr-aWeCTQ.png" /></figure><ul><li><strong>What it does:</strong> Displays memory usage in human-readable format.</li><li><strong>Why:</strong> Quickly know available memory and swap usage.</li></ul><p><strong>2. Check Disk Usage</strong></p><pre>df -h</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*He7PMcngiY3aaZ73x32Nww.png" /></figure><ul><li><strong>What it does:</strong> Shows mounted filesystems, used/available space.</li><li><strong>Why:</strong> Prevent disk full issues that can crash services.</li></ul><pre>du -sh /var/log/*</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*KxEVvUa1_6zoO-Q7rmQ7dA.png" /></figure><ul><li><strong>What it does:</strong> Shows size of log directories/files.</li><li><strong>Why:</strong> Identify which logs are consuming space.</li></ul><p><strong>3. Monitor Logs</strong></p><pre>journalctl -p err -b</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*Xr0oqNHzI490wClsM8QgPA.png" /></figure><ul><li><strong>What it does:</strong> Displays system errors from the current boot.</li><li><strong>Why:</strong> Quickly spot critical system issues.</li></ul><pre>tail -n 20 /var/log/messages</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*-lAUlCbWLz7rPA00o5fRFg.png" /></figure><ul><li><strong>What it does:</strong> Shows last 20 lines of system messages.</li><li><strong>Why:</strong> Keeps you updated with recent system events.</li><li><strong>Reason:</strong> Identify high-resource processes and available memory also Detect critical system issues quickly.</li></ul><h3>2. Create Full Daily Maintenance Script</h3><p>Create the script:</p><pre>sudo vim /usr/local/bin/daily_maintenance.sh</pre><p>Paste this <strong>ready-to-run script</strong>:</p><pre>#!/bin/bash<br>set -eu<br><br># Daily Maintenance Script<br>REPORT_FILE=&quot;/tmp/system_report_$(date +%F).txt&quot;<br>LOG_ARCHIVE=&quot;/tmp/logs_$(date +%F).tar.gz&quot;<br>OLD_LOG_LIST=&quot;/tmp/old_logs.txt&quot;<br><br># 1. System Resource Report<br>echo &quot;Daily System Report - $(date)&quot; &gt; $REPORT_FILE<br>echo &quot;-----------------------------&quot; &gt;&gt; $REPORT_FILE<br>echo &quot;Memory Usage:&quot; &gt;&gt; $REPORT_FILE<br>free -h &gt;&gt; $REPORT_FILE<br>echo &quot;&quot; &gt;&gt; $REPORT_FILE<br>echo &quot;Disk Usage:&quot; &gt;&gt; $REPORT_FILE<br>df -h &gt;&gt; $REPORT_FILE<br>echo &quot;&quot; &gt;&gt; $REPORT_FILE<br>echo &quot;Top 5 CPU Consuming Processes:&quot; &gt;&gt; $REPORT_FILE<br>ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head -n 6 &gt;&gt; $REPORT_FILE<br>echo &quot;&quot; &gt;&gt; $REPORT_FILE<br><br># 2. Find Logs Older Than 7 Days<br>find /var/log -type f -mtime +7 &gt; $OLD_LOG_LIST<br><br># 3. Archive Old Logs (only if they exist)<br>if [ -s $OLD_LOG_LIST ]; then<br>   if tar -czf $LOG_ARCHIVE -T $OLD_LOG_LIST; then<br>    xargs rm -f &lt; $OLD_LOG_LIST<br>    echo &quot;Old logs archived to $LOG_ARCHIVE&quot; &gt;&gt; $REPORT_FILE<br>else<br>    echo &quot;Log archive FAILED!&quot; &gt;&gt; $REPORT_FILE<br>fi<br>else<br> echo &quot;No logs older than 7 days found.&quot; &gt;&gt; $REPORT_FILE<br>fi<br><br># 4. Send Email Report<br>mail -s &quot;Daily System Report&quot; yourgmailcom &lt; $REPORT_FILE<br><br># 5. Cleanup Temporary Files Older Than 7 Days<br>find /tmp -type f -mtime +7 -delete</pre><h3>Script Explanation</h3><h4>Script Header</h4><pre>#!/bin/bash</pre><ul><li>Specifies the interpreter used to execute the script.</li><li>Ensures the script runs using the <strong>Bash shell</strong>.</li></ul><h4>Prevent Silent Failures</h4><pre>set -eu</pre><p>set -e</p><ul><li>Stops the script if any command fails.</li><li>Prevents the script from continuing when an error occurs.</li></ul><p>set -u</p><ul><li>Stops the script if an undefined variable is used.</li><li>Helps prevent mistakes caused by typos in variable names.</li></ul><p><strong>Reason this was added</strong></p><ul><li>Prevents silent failures in automation scripts.</li><li>Ensures errors are detected immediately.</li></ul><h4>How Errors Can Be Detected</h4><p>If the script stops due to an error, it can be detected in several ways:</p><h4><strong>Exit status</strong></h4><p>After running the script, the exit code can be checked:</p><pre>echo $?</pre><ul><li>0 indicates the script executed successfully.</li><li>Any other value indicates that an error occurred.</li></ul><h4><strong>Running the script in debug mode</strong></h4><p>The script can be executed with command tracing enabled:</p><pre>bash -x daily_maintenance.sh</pre><ul><li>This displays each command as it runs and helps identify the exact point where the script failed.</li></ul><h4><strong>Checking system or mail logs</strong></h4><p>If the failure occurs during email delivery, logs can be reviewed:</p><pre>sudo tail -f /var/log/maillog</pre><ul><li>This confirms whether the email was successfully sent or if an SMTP error occurred.</li></ul><h4>How to Detect and Stop the Script</h4><ol><li><strong>Check if the script is running</strong>:</li></ol><pre>ps aux |  grep daily_maintenance.sh</pre><ul><li>Look for your script’s <strong>PID</strong> (ignore the grep line itself).</li></ul><ol><li><strong>Stop the script</strong>:</li></ol><ul><li>If running in the foreground: Ctrl + C</li><li>If running in the background: kill &lt;PID&gt;</li><li>Force stop if necessary: kill -9 &lt;PID&gt;</li></ul><ol><li><strong>Check script exit status</strong>:</li></ol><pre>echo $?</pre><ul><li>0 → success</li><li>Non-zero → error occurred</li></ul><ol><li><strong>Use debug mode</strong>:</li></ol><pre>bash -x daily_maintenance.sh</pre><ul><li>Shows every command as it executes.</li><li>Helps identify exactly where the script failed.</li></ul><p><strong>Check email or log files</strong>:</p><ul><li>If the script sends email, check /var/log/maillog to see if the report was delivered.</li><li>If logging is enabled, review /var/log/daily_maintenance.log for errors.</li></ul><h4>Variables Used</h4><pre>REPORT_FILE=&quot;/tmp/system_report_$(date +%F).txt&quot;</pre><ul><li>Stores the location of the system report.</li><li>$(date +%F) inserts the current date in YYYY-MM-DD format.</li><li>This ensures each report has a <strong>unique filename</strong>.</li></ul><p>Example:</p><pre>/tmp/system_report_2026-03-14.txt</pre><pre>LOG_ARCHIVE=&quot;/tmp/logs_$(date +%F).tar.gz&quot;</pre><ul><li>Defines the archive file where old logs will be compressed.</li><li>Uses the .tar.gz format for compressed archives.</li></ul><p>Example:</p><pre>/tmp/logs_2026-03-14.tar.gz</pre><pre>OLD_LOG_LIST=&quot;/tmp/old_logs.txt&quot;</pre><ul><li>Temporary file used to store the list of log files older than 7 days.</li></ul><h4>System Resource Report</h4><pre>echo &quot;Daily System Report - $(date)&quot; &gt; $REPORT_FILE</pre><ul><li>Creates the report file.</li><li>Writes the report header with the current date and time.</li></ul><pre>echo &quot;-----------------------------&quot;</pre><ul><li>Adds a separator for readability.</li></ul><h4>Memory Usage Section</h4><pre>free -h</pre><ul><li>Displays system memory usage.</li><li>h means human-readable output (MB, GB).</li></ul><p>The result is appended to the report file.</p><h4>Disk Usage Section</h4><pre>df -h</pre><ul><li>Displays disk space usage for all mounted filesystems.</li><li>Helps detect when disks are nearing capacity.</li></ul><p>The output is added to the report file.</p><h4>Top CPU Consuming Processes</h4><pre>ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head -n 6</pre><ul><li>Displays running processes.</li><li>Shows the following information:</li><li>Process ID</li><li>Parent Process ID</li><li>Command running</li><li>Memory usage</li><li>CPU usage</li></ul><p>-sort=-%cpu</p><ul><li>Sorts processes by highest CPU usage.</li></ul><p>head -n 6</p><ul><li>Displays the top 5 CPU-consuming processes plus the header.</li></ul><h4>Find Old Logs</h4><pre>find /var/log -type f -mtime +7</pre><ul><li>Searches the /var/log directory.</li><li>type f selects files only.</li><li>mtime +7 selects files older than 7 days.</li></ul><p>The results are stored in:</p><pre>/tmp/old_logs.txt</pre><h4>Check if Old Logs Exist</h4><pre>if [ -s $OLD_LOG_LIST ]</pre><ul><li>Checks whether the file exists and contains data.</li></ul><p><strong>Reason</strong></p><ul><li>Prevents the script from creating empty archives when no old logs exist.</li></ul><h4>Archive Old Logs</h4><pre>tar -czf $LOG_ARCHIVE -T $OLD_LOG_LIST</pre><ul><li>Creates a compressed archive of all logs listed in old_logs.txt.</li></ul><p>Options used:</p><ul><li>c create archive</li><li>z compress with gzip</li><li>f specify filename</li><li>T read file list from a file</li></ul><h4>Remove Archived Logs</h4><pre>xargs rm -f &lt; $OLD_LOG_LIST</pre><ul><li>Deletes the log files after they have been successfully archived.</li><li>Ensures logs are not deleted unless archiving succeeded.</li></ul><h4>Log Archive Status</h4><pre>echo &quot;Old logs archived to $LOG_ARCHIVE&quot;</pre><ul><li>Adds a success message to the report.</li></ul><p>If archiving fails:</p><pre>echo &quot;Log archive FAILED!&quot;</pre><ul><li>Records the error in the report.</li></ul><h4>Email the Report</h4><pre>mail -s &quot;Daily System Report&quot; bamidelebabatundem@gmail.com &lt; $REPORT_FILE</pre><ul><li>Sends the report via email.</li><li>Uses Gmail SMTP through the Postfix configuration.</li><li>The report file becomes the body of the email.</li></ul><h4>Clean Temporary Files</h4><pre>find /tmp -type f -mtime +7 -delete</pre><ul><li>Searches for files in /tmp older than 7 days.</li><li>Deletes them automatically.</li></ul><p><strong>Reason</strong></p><ul><li>Prevents accumulation of unnecessary temporary files.</li></ul><h4>Summary of What the Script Does</h4><p>When executed, the script:</p><ul><li>generates a <strong>daily system report</strong></li><li>records <strong>memory usage</strong></li><li>records <strong>disk usage</strong></li><li>lists <strong>top CPU-consuming processes</strong></li><li>finds logs older than 7 days</li><li>compresses them into an archive</li><li>deletes archived logs</li><li>emails the report to Gmail</li><li>removes old temporary files</li></ul><h3>Make the script executable:</h3><pre>sudo chmod +x /usr/local/bin/daily_maintenance.sh</pre><h3>3. Install Mail Utility</h3><p>Install the mail utility so the script can send system reports by email.</p><p>The mail command is not installed by default on RHEL. Installing <strong>mailx</strong> allows the script to send automated system reports to your email.</p><h3>Gmail Email Notification Setup</h3><h4>Step 1 — Install Postfix</h4><pre>sudo dnf install postfix -y</pre><p><strong>Explanation</strong></p><p>Postfix is the <strong>Mail Transfer Agent (MTA)</strong> responsible for sending emails from the server.</p><h4>Step 2 — Start and Enable Postfix</h4><pre>sudo systemctl enable --now postfix</pre><p><strong>Explanation</strong></p><ul><li>enable → starts postfix automatically when the system boots.</li><li>-now → starts the service immediately.</li></ul><h4>Step 3 — Install Mail Utility</h4><pre>sudo dnf install mailx -y</pre><p><strong>Explanation</strong></p><p>mailx (also called <strong>s-nail</strong>) allows scripts and users to <strong>send emails from the command line</strong>.</p><p>This troubleshooting process helped me determine that the problem was not simply the mail command. The message was being handed to Postfix, but external delivery required Postfix to communicate with an SMTP server.</p><p>Therefore, the next step was to configure Postfix to use an authenticated SMTP relay, in this case Gmail’s SMTP service.</p><p>Before configuring SMTP authentication, I installed the required SASL packages (Authentication Libraries)</p><h4>Step 4 — Install Authentication Libraries</h4><pre>sudo dnf install cyrus-sasl cyrus-sasl-plain -y</pre><p><strong>Explanation</strong></p><p>These packages allow Postfix to <strong>authenticate with Gmail SMTP</strong> using your email and App Password.</p><h4>Step 5 — Configure Gmail SMTP Relay</h4><p>Edit the postfix configuration file:</p><pre>sudo vim /etc/postfix/main.cf</pre><p>Add the following lines at the bottom:</p><pre>relayhost = [smtp.gmail.com]:587<br><br>smtp_use_tls = yes<br>smtp_tls_security_level = encrypt<br>smtp_sasl_auth_enable = yes<br>smtp_sasl_password_maps = lmdb:/etc/postfix/sasl_passwd<br>smtp_sasl_security_options = noanonymous<br>smtp_sasl_tls_security_options = noanonymous<br>smtp_sasl_mechanism_filter = plain, login<br>smtp_tls_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1<br>smtp_tls_mandatory_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1<br><br>inet_protocols = ipv4</pre><p><strong>Explanation</strong></p><p>These settings allow your server to <strong>send email through Gmail securely</strong>.</p><h4>relayhost = [smtp.gmail.com]:587</h4><ul><li>Specifies that Postfix will <strong>send all outgoing mail through Gmail’s SMTP server</strong>.</li><li>[smtp.gmail.com] → square brackets prevent Postfix from doing a DNS MX lookup (tells Postfix this is a direct host).</li><li>:587 → port 587 is the <strong>SMTP submission port with STARTTLS</strong> (secure connection).</li></ul><p><strong>Reason:</strong></p><ul><li>This is needed to use Gmail as an external mail relay for sending email from your RHEL server.</li></ul><h4>smtp_use_tls = yes</h4><ul><li>Enables <strong>TLS encryption</strong> for outgoing emails.</li><li>Ensures emails are sent securely instead of plain text.</li></ul><h4>smtp_tls_security_level = encrypt</h4><ul><li>Forces Postfix to <strong>always use TLS encryption</strong> when connecting to the relay host.</li><li>Mail will <strong>fail if TLS cannot be established</strong>.</li></ul><p><strong>Reason:</strong></p><ul><li>Gmail requires encrypted connections; this ensures compliance and security.</li></ul><h4>smtp_sasl_auth_enable = yes</h4><ul><li>Enables <strong>SASL authentication</strong> for outgoing SMTP.</li><li>SASL allows Postfix to log in to Gmail with a username and password (or app password).</li></ul><h4>smtp_sasl_password_maps = lmdb:/etc/postfix/sasl_passwd</h4><ul><li>Tells Postfix where to find <strong>SMTP credentials</strong> for authentication.</li><li>lmdb: is the database format used for storing username/password pairs securely.</li><li>/etc/postfix/sasl_passwd is the file containing your Gmail username and <strong>App Password</strong>.</li></ul><p>Example content of /etc/postfix/sasl_passwd:</p><pre>[smtp.gmail.com]:587 yourgmail:your_app_password</pre><h4>smtp_sasl_security_options = noanonymous</h4><ul><li>Prevents Postfix from trying <strong>anonymous login</strong>.</li><li>Ensures that it always uses the credentials provided in sasl_passwd.</li></ul><h4>smtp_sasl_tls_security_options = noanonymous</h4><ul><li>Ensures <strong>TLS-encrypted SASL authentication</strong>.</li><li>Gmail requires login credentials to be sent over TLS, not plain text.</li></ul><h4>smtp_sasl_mechanism_filter = plain, login</h4><ul><li>Limits Postfix to only use PLAIN or LOGIN mechanisms for SASL authentication.</li><li>These are the methods supported by Gmail.</li></ul><h4>smtp_tls_protocols</h4><pre>smtp_tls_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1</pre><p>This specifies which TLS/SSL protocol versions Postfix is allowed to use when establishing an SMTP connection.</p><p>The ! means <strong>exclude/disable</strong> that protocol. Therefore, Postfix will not use the outdated SSLv2, SSLv3, TLS 1.0, or TLS 1.1 protocols.</p><p><strong>Reason:</strong></p><p>These older protocols are obsolete and have known security weaknesses. Disabling them ensures that Postfix uses modern and more secure TLS versions, such as TLS 1.2 or TLS 1.3 when supported.</p><h4>smtp_tls_mandatory_protocols</h4><pre>smtp_tls_mandatory_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1</pre><p>This specifies which TLS/SSL protocol versions Postfix is allowed to use when <strong>TLS encryption is mandatory</strong>.</p><p>In our configuration, we have:</p><pre>smtp_tls_security_level = encrypt</pre><p>This means Postfix must establish an encrypted TLS connection with the SMTP server. Therefore, this setting prevents Postfix from using outdated protocols even when TLS is required.</p><p><strong>Reason:</strong></p><p>It provides an additional security layer by ensuring that mandatory TLS connections use only modern, secure protocol versions and cannot fall back to obsolete protocols.</p><h4>In simple terms:</h4><blockquote><strong><em>We disabled old TLS/SSL protocols because they are outdated and less secure, ensuring that our Postfix-to-Gmail SMTP connection uses modern encryption protocols.</em></strong></blockquote><p><strong>Note:</strong> These settings are for <strong>security hardening</strong>. They are not responsible for establishing the initial TCP connection to port 587.</p><h4>inet_protocols = ipv4</h4><ul><li>Tells Postfix to only use <strong>IPv4 connections</strong>.</li><li>Avoids errors if IPv6 is misconfigured or Gmail’s IPv6 connection fails.</li></ul><h4>Summary</h4><p>This configuration tells Postfix to:</p><ol><li>Use <strong>Gmail’s SMTP server</strong> to send mail.</li><li>Always use <strong>TLS encryption</strong>.</li><li>Authenticate with your <strong>Gmail username + App Password</strong>.</li><li>Only allow <strong>secure login mechanisms</strong>.</li><li>Use <strong>IPv4</strong> to avoid network errors.</li></ol><h4>Step 6 — Create Gmail Authentication File</h4><p><strong>Important Note:</strong></p><p>Gmail does not allow normal account passwords for SMTP authentication.</p><p>To use Gmail with Postfix you must:</p><ol><li>On your Google account, Click on S<strong>ecurity and Sign-in</strong></li><li>Click on <strong>2-Step Verification,</strong> Turn on <strong>2-Step Verification</strong></li><li>To generate a <strong>Google App Password</strong> from your Google security settings</li><li>On <strong>Security and Sign-in,</strong> Search for <strong>App Passwords</strong></li><li>App Name: <strong>Mail</strong></li><li>Click on <strong>Create</strong></li><li>Use the generated <strong>App Password</strong> instead of your Gmail password in the authentication line</li></ol><p><strong>Note:</strong> <em>When inserting password in the authentication line, you do not add the space type it together</em></p><p>Type:</p><pre>sudo vim /etc/postfix/sasl_passwd</pre><p>Add:</p><pre>[smtp.gmail.com]:587 yourgmail:YOUR_APP_PASSWORD</pre><p><em>Replace yourgmail:YOUR_APP_PASSWORD with your actual gmail &amp; Password you generated from google app</em></p><p><strong>Explanation</strong></p><p>This file stores the <strong>Gmail login credentials</strong> used by Postfix.</p><p>⚠️ Use a <strong>Google App Password</strong>, not your normal Gmail password.</p><h4>Step 7 — Generate Database File</h4><pre>sudo postmap lmdb:/etc/postfix/sasl_passwd</pre><p>This creates:</p><pre>/etc/postfix/sasl_passwd.lmdb</pre><p><strong>Explanation</strong></p><p>Postfix reads the <strong>database version</strong> of the file for faster lookups.</p><h4>Resolving Duplicate Postfix Parameters</h4><p>While generating the SASL password database, Postfix displayed warnings indicating that two parameters in main.cf had been defined more than once:</p><pre>warning: /etc/postfix/main.cf: line 754: overriding earlier entry: smtp_tls_security_level=may<br>warning: /etc/postfix/main.cf: line 762: overriding earlier entry: inet_protocols=all</pre><p>I checked the configuration and found that these parameters already existed earlier in /etc/postfix/main.cf, while I had added new values at the bottom for the Gmail SMTP configuration.</p><p>The existing entries were commented out instead of being deleted:</p><pre>#smtp_tls_security_level = may<br>#inet_protocols = all</pre><p>The active settings were then kept in the Gmail SMTP configuration:</p><pre>smtp_tls_security_level = encrypt<br>inet_protocols = ipv4</pre><p>This ensures that each parameter has one active configuration value and prevents Postfix from reporting duplicate-setting warnings.</p><p>I then verified the Postfix configuration:</p><pre>sudo postfix check</pre><p>Finally, I regenerated the SASL password database:</p><pre>sudo postmap lmdb:/etc/postfix/sasl_passwd</pre><p>With the duplicate parameters resolved and the configuration check passing, the Postfix configuration was ready for the next stage of testing.</p><h4>Step 8 — Secure the Credentials</h4><pre>sudo chmod 600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.lmdb</pre><p><strong>Explanation</strong></p><p>Only the <strong>root user</strong> can read the password file.</p><h4>Step 9 — Restart Postfix</h4><pre>sudo systemctl restart postfix</pre><p><strong>Explanation</strong></p><p>Applies the new configuration.</p><h4>Step 10 — Test Email</h4><p><strong>Test SMTP port connectivity:</strong></p><pre>nc -zv smtp.gmail.com 587</pre><p><strong>Send test mail:</strong></p><pre>echo &quot;Test Mail from RHEL Server&quot; | mail -s &quot;Test Email&quot; yourgmail</pre><p>If configured correctly, the message will arrive in your Gmail.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/1*Rl4HedSL9vItBjV36K1SDQ.jpeg" /></figure><h4>Step 11 — Check Mail Logs (Optional)</h4><pre>sudo tail -f /var/log/maillog</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*09rhBE4LwZbhesnMSQJluA.png" /></figure><h3>5. Schedule the Script to Run Daily</h3><h4>Option A: Using cron (Simpler)</h4><ol><li>Open the root user’s cron table:</li></ol><pre>sudo crontab -e</pre><ol><li>Add this line (runs every day at 7 AM):</li></ol><pre>0 7 * * * /usr/local/bin/daily_maintenance.sh</pre><ul><li><strong>Reason:</strong> Cron is lightweight and perfect for daily tasks.</li></ul><h4>Option B: Using systemd timer (Advanced)</h4><p>Create a systemd service file:</p><pre>sudo vim /etc/systemd/system/daily_maintenance.service</pre><p>Paste:</p><pre>[Unit]<br>Description=Daily Maintenance Script</pre><pre>[Service]<br>Type=oneshot<br>ExecStart=/usr/local/bin/daily_maintenance.sh</pre><p>Create a timer file:</p><pre>sudo vim /etc/systemd/system/daily_maintenance.timer</pre><p>Paste:</p><pre>[Unit]<br>Description=Run Daily Maintenance Script every day at 7 AM</pre><pre>[Timer]<br>OnCalendar=*-*-* 07:00:00<br>Persistent=true</pre><pre>[Install]<br>WantedBy=timers.target</pre><p>Enable and start the timer:</p><pre>sudo systemctl daemon-reload<br>sudo systemctl enable --now daily_maintenance.timer<br>sudo systemctl start daily_maintenance.timer</pre><ul><li><strong>Reason:</strong> systemd timers provide better logging, retries, and control over execution.</li></ul><h3>6. Test the Script</h3><pre>sudo /usr/local/bin/daily_maintenance.sh<br>cat /tmp/system_report_$(date +%F).txt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qx8pAKE1nrFtWZUz0CwxHQ.png" /></figure><ul><li><strong>Reason:</strong> Ensure the script works correctly before scheduling.</li></ul><h3>7. Remove the cron entry</h3><p>We removed <strong>crontab because we decided to use systemd timers as the single scheduler</strong> for this project — not because cron is bad.</p><p>The main reason was <strong>avoiding duplicate execution</strong>.</p><p>Run:</p><pre>sudo crontab -e</pre><p>You’ll see:</p><pre>0 7 * * * /usr/local/bin/daily_maintenance.sh</pre><p>Delete that line, save, and exit.</p><p>Since you prefer Vim:</p><ul><li>Press dd on the line to delete it.</li><li>Press Esc</li><li>Type:</li></ul><pre>:wq</pre><p>Then verify:</p><pre>sudo crontab -l</pre><p>You should get:</p><pre>no crontab for root</pre><p>or an empty crontab.</p><h4>Then verify our official scheduler</h4><pre>sudo systemctl status daily_maintenance.timer</pre><p>and:</p><pre>sudo systemctl list-timers daily_maintenance.timer</pre><p>After that, <strong>don’t change anything else</strong>.</p><p><strong>Finally, the Scheduled “Daily System Report” Delivered successfully as seen below</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*RUqBBCC1_IEJX4oT1gbs8A.jpeg" /></figure><h3>Conclusion</h3><p>In this project, I automated daily system monitoring and maintenance on RHEL using Bash scripting and systemd timers. The solution monitors system resources, manages old logs, generates daily reports, and sends them through email using Postfix and Gmail SMTP.</p><p>This project provided practical experience with Linux automation, system monitoring, log management, email configuration, Bash scripting, and systemd timers while reducing the need for manual administrative tasks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=efae6df7a436" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RHEL 10 Lab: Recovering a Broken /etc/fstab and Troubleshooting Automatic Filesystem Mounting]]></title>
            <link>https://medium.com/@bamidelebabatundem/rhel-10-lab-recovering-a-broken-etc-fstab-and-troubleshooting-automatic-filesystem-mounting-ecbc30b9fdda?source=rss-99476dec8c94------2</link>
            <guid isPermaLink="false">https://medium.com/p/ecbc30b9fdda</guid>
            <category><![CDATA[configuration-file]]></category>
            <category><![CDATA[configuration]]></category>
            <category><![CDATA[boots]]></category>
            <dc:creator><![CDATA[Babatunde]]></dc:creator>
            <pubDate>Mon, 12 Oct 2026 15:29:22 GMT</pubDate>
            <atom:updated>2026-10-12T15:29:22.190Z</atom:updated>
            <content:encoded><![CDATA[<h3>Objective</h3><p>To learn how to recover a RHEL system that fails to boot because of an incorrect root filesystem UUID in /etc/fstab, use rd.break to access the recovery environment, repair the configuration, and troubleshoot automatic mounting of an XFS filesystem.</p><h3>1. Introduction</h3><p>The /etc/fstab file contains information about filesystems that Linux should mount during startup. If an important entry is incorrect, the system may fail to boot normally.</p><p>During this lab, I intentionally changed the root filesystem UUID in /etc/fstab. This caused a boot problem, and I had to use the GRUB boot menu and the rd.break kernel parameter to access the recovery environment.</p><p>I then located the installed system under /sysroot, remounted it as read-write, and corrected the configuration using Vim.</p><p>After recovering the system, I continued troubleshooting a separate XFS filesystem that I wanted to mount automatically at /mnt.</p><h3>2. Lab Environment</h3><ul><li>Operating system: Red Hat Enterprise Linux 10</li><li>Virtualization: VMware</li><li>Filesystem type: XFS</li><li>Root filesystem: /dev/mapper/rhel-root</li><li>Additional filesystem: /dev/sda1</li><li>Additional mount point: /mnt</li><li>Configuration file: /etc/fstab</li><li>Text editor: Vim</li></ul><h3>3. Intentionally Breaking /etc/fstab</h3><p>During the experiment, I modified the root filesystem UUID in /etc/fstab by adding an extra e.</p><p>The correct root UUID was:</p><pre>dd504084e-fb51-4e85-b7db-59b1b5819ff0</pre><p>I changed it to the incorrect UUID:</p><pre>edd504084e-fb51-4e85-b7db-59b1b5819ff0</pre><p>Because the root filesystem entry was incorrect, RHEL could not correctly resolve the configured root filesystem during startup. This prevented the system from completing a normal boot.</p><p>This demonstrated why /etc/fstab must be edited carefully.</p><h3>4. Entering the Recovery Environment</h3><p>Since the system could not boot normally, I needed to interrupt the boot process and enter the early boot recovery environment.</p><h3>Step 1: Reboot the Virtual Machine</h3><p>Restart the RHEL virtual machine in VMware.</p><p>When the GRUB boot menu appears, select the normal RHEL boot entry.</p><h3>Step 2: Edit the GRUB Entry</h3><p>Press:</p><pre>e</pre><p>This opens the boot entry for editing.</p><p>Locate the line that begins with linux or, depending on the boot configuration, linuxefi. It contains the kernel parameters.</p><p>The line may resemble:</p><pre>linux /vmlinuz-... root=/dev/mapper/rhel-root ro ...</pre><h3>Step 3: Add rd.break</h3><p>Move to the end of the Linux kernel parameter line and add:</p><pre>rd.break</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/1*kIm5ZAjEaxhuBttfCk0kiQ.png" /></figure><p>What does rd.break do?</p><p>rd.break tells the RHEL initial RAM disk environment, known as dracut, to pause the boot process and provide a recovery shell before the normal root filesystem handoff.</p><p>This is useful when a problem with an early boot configuration prevents the system from starting normally.</p><h3>Step 4: Boot With the Modified Parameters</h3><p>Press:</p><pre>Ctrl + X</pre><p>RHEL will boot using the temporary kernel parameter.</p><p>Instead of reaching the normal login screen, it should stop at the dracut recovery shell.</p><p>Important: The GRUB change is temporary. It does not permanently modify the system’s boot configuration.</p><h3>5. Locating the Installed Root Filesystem</h3><p>In the dracut recovery environment, I was not working inside the normal running RHEL system.</p><p>The installed system’s root filesystem was accessible at:</p><pre>/sysroot</pre><p>This distinction matters because the recovery environment has its own root directory.</p><p>The installed system’s files are available beneath /sysroot, including:</p><pre>/sysroot/etc/fstab</pre><p>That is the file I needed to repair.</p><p>Important: Editing /etc/fstab inside the temporary recovery environment is not necessarily the same as editing the installed system&#39;s configuration. In this situation, the correct target was /sysroot/etc/fstab.</p><h3>6. Making /sysroot Writable</h3><p>The installed root filesystem was initially mounted read-only. I needed to remount it as read-write before changing its configuration.</p><h3>Step 1: Check the Mount Status</h3><p>Run:</p><pre>mount | grep sysroot</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*vExZm4tGvLQ2s_6Q_MR0qQ.png" /></figure><p>Explanation:</p><ul><li>mount displays information about mounted filesystems.</li><li>| sends the output of the first command to the next command.</li><li>grep sysroot filters the output to lines containing sysroot.</li></ul><p>This helps identify how the installed root filesystem is mounted.</p><h3>Step 2: Remount the Filesystem as Read-Write</h3><p>Run:</p><pre>mount -o remount,rw /sysroot</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*k3-dWWZTG2ic3wFezEX90w.png" /></figure><p>Command breakdown:</p><ul><li>mount manages filesystem mounts.</li><li>o specifies mount options.</li><li>remount changes the options of an already-mounted filesystem.</li><li>rw means read-write.</li><li>/sysroot is the mount point of the installed RHEL system.</li></ul><p>The command requests that the installed root filesystem be remounted with write access.</p><h3>Step 3: Verify the Mount Options</h3><p>Run:</p><pre>mount | grep sysroot</pre><p>Look for rw in the mount options.</p><p>For example:</p><pre>/dev/mapper/rhel-root on /sysroot type xfs (rw,...)</pre><p>The important part is rw, which indicates read-write access.</p><h3>7. Repairing the Root UUID in /etc/fstab</h3><p>Once /sysroot was writable, I opened the installed system&#39;s configuration file with Vim.</p><p>Run:</p><pre>vim /sysroot/etc/fstab</pre><p>Locate the root filesystem entry and correct the UUID.</p><p>The correct entry was:</p><pre>UUID=dd504084e-fb51-4e85-b7db-59b1b5819ff0 / xfs defaults 0 0</pre><h3>Understanding the Entry</h3><ul><li>UUID=... identifies the filesystem by its unique identifier.</li><li>/ is the root mount point.</li><li>xfs is the filesystem type.</li><li>defaults applies the standard mount options.</li><li>The first 0 controls the legacy dump backup field.</li><li>The second 0 disables the legacy fsck pass for this entry.</li></ul><p>The UUID must match the actual root filesystem.</p><p>To inspect filesystem UUIDs when the relevant devices are available, use:</p><pre>blkid</pre><p>Or:</p><pre>lsblk -f</pre><p>These commands display information about block devices, filesystems, and their UUIDs.</p><h3>Saving the File in Vim</h3><p>After correcting the UUID:</p><ol><li>Press Esc.</li><li>Type :wq.</li><li>Press Enter.</li></ol><p>:wq saves the changes and exits Vim.</p><h3>8. Rebooting After the Repair</h3><p>After correcting the installed system’s /etc/fstab, reboot the virtual machine.</p><p>Run this from the recovery shell:</p><pre>reboot</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*mRscGU3Bok6g_my4YknAkg.gif" /></figure><p>If the correction is successful, RHEL should be able to continue its normal startup process.</p><p>The recovery process was:</p><pre>Incorrect root UUID in /etc/fstab<br>                 |<br>                 v<br>        Normal boot fails<br>                 |<br>                 v<br>          GRUB boot menu<br>                 |<br>                 v<br>          Press e to edit<br>                 |<br>                 v<br>           Add rd.break<br>                 |<br>                 v<br>            Press Ctrl+X<br>                 |<br>                 v<br>       Dracut recovery shell<br>                 |<br>                 v<br>       Installed system at /sysroot<br>                 |<br>                 v<br>mount -o remount,rw /sysroot<br>                 |<br>                 v<br>    vim /sysroot/etc/fstab<br>                 |<br>                 v<br>        Correct the UUID<br>                 |<br>                 v<br>              Reboot</pre><h3>9. Troubleshooting the Additional XFS Filesystem</h3><p>After recovering the system, I continued working on a separate filesystem that I wanted to mount automatically at /mnt.</p><p>The partition was:</p><pre>/dev/sda1</pre><p>Its UUID was:</p><pre>246b79f1-da5e-4244-9917-8de7441eaa3d</pre><p>The intended /etc/fstab entry was:</p><pre>UUID=246b79f1-da5e-4244-9917-8de7441eaa3d /mnt xfs defaults 0 0</pre><p>This tells RHEL to mount the filesystem identified by that UUID at /mnt, using XFS and the default mount options.</p><h3>Step 1: Test the fstab Configuration</h3><p>Run:</p><pre>sudo mount -a</pre><p>Explanation:</p><ul><li>sudo runs the command with administrative privileges.</li><li>mount manages filesystem mounts.</li><li>a attempts to mount applicable filesystems listed in /etc/fstab that are not already mounted.</li></ul><p>The command completed without an error, and the filesystem mounted at /mnt.</p><p>Note: A successful mount -a confirms that the applicable entries can be mounted at that moment. It does not, by itself, prove that mounting will succeed after a reboot.</p><h3>Step 2: Confirm the Filesystem Is Mounted</h3><p>Run:</p><pre>df -hT /mnt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*m-cv0wa1AJQR3Uz93tVDag.png" /></figure><p>Explanation:</p><ul><li>df displays filesystem disk usage.</li><li>h displays sizes in human-readable units.</li><li>T includes the filesystem type.</li><li>/mnt specifies the filesystem to inspect.</li></ul><p>The output showed /dev/sda1 as an XFS filesystem mounted at /mnt.</p><h3>Step 3: Inspect the Mount</h3><p>Run:</p><pre>findmnt /mnt</pre><p>This displays the filesystem associated with /mnt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xWYFF2j3xVkyOAJFQULQ4g.png" /></figure><p>It confirmed that /dev/sda1 was mounted there.</p><h3>Step 4: Check the fstab Entry</h3><p>Run:</p><pre>findmnt --fstab /mnt</pre><p>This checks the mount definition in /etc/fstab for /mnt, rather than simply reporting the current live mount.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*I4lyEQEHbNy0NxZnetcToQ.png" /></figure><p>It showed the expected UUID, mount point, and filesystem type.</p><h3>Step 5: Validate the fstab Configuration</h3><p>Run:</p><pre>sudo findmnt --verify</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*s1XogrRVd1H4WPjOZ0ZkWQ.png" /></figure><p>This indicated that the current mount configuration passed this validation check.</p><h3>10. Investigating the SELinux Message</h3><p>During troubleshooting, the journal reported an SELinux access issue involving the systemd GPT auto-generator and /etc/fstab.</p><p>The message included:</p><pre>SELinux is preventing /usr/lib/systemd/system-generators/systemd-gpt-auto-generator from read access on the file /etc/fstab.</pre><p>The expected SELinux type for /etc/fstab is etc_t.</p><p>To inspect the current context, I ran:</p><pre>ls -Z /etc/fstab</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*8LJwoyDaO1xbossDgzlBrg.png" /></figure><p>The file therefore had the expected SELinux type when checked.</p><p>This was useful diagnostic evidence, but it did not establish that SELinux was the cause of the separate /mnt mount issue. The exact cause of that persistence issue was not conclusively established by the checks performed.</p><h3>11. Understanding systemd and fstab</h3><p>RHEL uses systemd during startup. Systemd has a generator called systemd-fstab-generator that reads /etc/fstab and creates mount-unit configuration for systemd.</p><p>During the investigation, the generated configuration for /mnt included the expected device UUID, mount point, and XFS filesystem type.</p><p>This helped confirm that the entry could be interpreted by the generator. However, generating a mount unit manually is not the same as proving that the normal boot process will use it successfully.</p><p>To reload systemd’s unit configuration, run:</p><pre>sudo systemctl daemon-reload</pre><p>This asks systemd to reload its unit configuration and rerun applicable generators.</p><p>To inspect the mount’s current state:</p><pre>findmnt /mnt</pre><p>To inspect boot-related errors after starting the system:</p><pre>journalctl -b -p err</pre><p>Explanation:</p><ul><li>journalctl displays systemd journal logs.</li><li>b restricts the results to the current boot.</li><li>p err filters for error-priority messages.</li></ul><p>These checks can help diagnose a mount that works manually but does not appear after reboot.</p><h3>12. Final Verification</h3><p>After making a filesystem entry in /etc/fstab, use the following checks.</p><p>Check filesystem UUIDs:</p><pre>lsblk -f</pre><p>Test fstab entries:</p><pre>sudo mount -a</pre><p>Confirm the live mount:</p><pre>findmnt /mnt</pre><p>Check the configured mount:</p><pre>findmnt --fstab /mnt</pre><p>Validate fstab entries:</p><pre>sudo findmnt --verify</pre><p>Check recent boot errors if needed:</p><pre>journalctl -b -p err</pre><p>For a final persistence test, reboot the system and run:</p><pre>findmnt /mnt</pre><p>If /mnt is present after reboot, that confirms the filesystem is mounted in the newly booted system. If it is absent, inspect the current boot journal and systemd mount-unit status to identify the cause.</p><h3>13. What I Learned</h3><ul><li>An incorrect root UUID in /etc/fstab can prevent normal startup.</li><li>GRUB can be used to add a temporary kernel parameter for recovery.</li><li>rd.break provides access to the early boot dracut environment.</li><li>The installed system’s root filesystem may be accessible under /sysroot.</li><li>The installed root filesystem may initially be read-only.</li><li>mount o remount,rw /sysroot requests read-write access.</li><li>The correct recovery target is /sysroot/etc/fstab.</li><li>blkid and lsblk f help identify filesystem UUIDs.</li><li>mount a tests whether applicable fstab entries can be mounted.</li><li>findmnt helps inspect both active mounts and configured mount entries.</li><li>findmnt -verify validates the mount configuration.</li><li>SELinux context and systemd journal messages can provide useful troubleshooting clues.</li><li>A successful manual mount does not automatically prove that the filesystem will mount at boot.</li></ul><h3>Conclusion</h3><p>In this lab, I intentionally introduced an incorrect root filesystem UUID and recovered the RHEL system using GRUB and rd.break. I accessed the installed system through /sysroot, made the filesystem writable, corrected /sysroot/etc/fstab, and rebooted.</p><p>I then investigated a separate XFS filesystem intended to mount at /mnt, using mount -a, df, findmnt, and findmnt --verify to check its configuration and active mount state.</p><p>This exercise strengthened my understanding of the RHEL boot process, filesystem UUIDs, /etc/fstab, recovery procedures, and systematic Linux troubleshooting.</p><p>Lab Complete.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ecbc30b9fdda" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ansible Automation of Apache Web Server Deployment and Firewall Configuration on RHEL 10]]></title>
            <link>https://medium.com/@bamidelebabatundem/ansible-automation-of-apache-web-server-deployment-and-firewall-configuration-on-rhel-10-a9f31b7fc811?source=rss-99476dec8c94------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9f31b7fc811</guid>
            <category><![CDATA[rhel-10]]></category>
            <category><![CDATA[ansible-tutorial]]></category>
            <category><![CDATA[ssh]]></category>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[ansible-playbook]]></category>
            <dc:creator><![CDATA[Babatunde]]></dc:creator>
            <pubDate>Mon, 08 Jun 2026 11:58:08 GMT</pubDate>
            <atom:updated>2026-06-08T11:58:08.949Z</atom:updated>
            <content:encoded><![CDATA[<h4>OBJECTIVE</h4><p>The objective of this practical is to use Ansible to automate the installation and configuration of an Apache web server on remote RHEL 10 systems. The practical also demonstrates how to configure firewall settings and deploy a custom web page automatically using a single Ansible playbook.</p><h4>INTRODUCTION</h4><p>Ansible is an open-source automation tool used for configuration management, application deployment, and task automation. It allows system administrators to manage multiple servers from a single control node without manually logging into each server.</p><p>Ansible uses SSH to communicate with managed nodes and does not require any agent software to be installed on the remote systems. Automation tasks are written in YAML files known as playbooks.</p><p>The major advantage of Ansible is its ability to automate repetitive administrative tasks, reduce human errors, and maintain consistent configurations across multiple servers.</p><p>In this practical, Ansible will be used to:</p><ul><li>Install Apache web server</li><li>Configure the firewall</li><li>Open HTTP access</li><li>Deploy a custom webpage</li></ul><p>During this practical, the following activities were carried out:</p><ol><li>Installed Ansible on the RHEL 10 Control Node.</li><li>Generated SSH keys for secure authentication.</li><li>Configured passwordless SSH access to managed nodes.</li><li>Created an Ansible inventory file.</li><li>Tested communication between the control node and managed nodes.</li><li>Created an Ansible playbook.</li><li>Installed Apache Web Server automatically.</li><li>Configured and enabled firewalld.</li><li>Opened HTTP traffic through the firewall.</li><li>Deployed a custom web page.</li><li>Verified successful deployment of Apache services.</li></ol><p><em>All tasks will be performed automatically on remote servers.</em></p><h4>LAB SETUP:</h4><ul><li><strong>Control Node:</strong> RHEL 10 system where Ansible is installed</li><li><strong>Managed Node:</strong> Remote RHEL server managed by Ansible</li><li><strong>Communication Method:</strong> SSH</li><li>Software Installed: Ansible</li></ul><p><strong>Managed Node 1:</strong></p><ul><li>IP Address: 192.168.65.134</li></ul><p><strong>Managed Node 2:</strong></p><ul><li>IP Address: 192.168.65.135</li></ul><p><strong>Web Service:</strong></p><ul><li>Apache HTTP Server (httpd)</li></ul><p><strong>Firewall Service:</strong></p><ul><li>firewalld</li></ul><h3>STEP 1 — INSTALL ANSIBLE</h3><p>Before Ansible can be used, it must first be installed on the control node. RHEL uses the DNF package manager to install software packages.</p><h4>Command:</h4><pre>sudo dnf install -y ansible-core</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8lc8F5H7PhA-N2rUc9NN7w.png" /></figure><h4>Command Explanation:</h4><ul><li>sudo runs the command with administrative privileges.</li><li>dnf is the package manager used in RHEL systems.</li><li>install tells the system to install a package.</li><li>-y automatically accepts installation prompts.</li><li>ansible-core is the main Ansible package being installed.</li></ul><h3>VERIFY ANSIBLE INSTALLATION</h3><p>After installation, the Ansible version is checked to confirm successful installation.</p><h4>Command:</h4><pre>ansible --version</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*RbV63LTZiZLiPu1CqfXLpQ.png" /></figure><h4>Command Explanation:</h4><ul><li>ansible runs the Ansible program.</li><li>-version displays the installed version and configuration details.</li></ul><h3>STEP 2 — GENERATE SSH KEY</h3><p>SSH keys are generated to enable secure passwordless authentication between the control node and managed nodes.</p><h4>Command:</h4><pre>ssh-keygen</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*SyFTBedQ5mO0aGQr-bv1nA.png" /></figure><h4>Command Explanation:</h4><ul><li>ssh-keygen generates SSH public and private authentication keys.</li></ul><h3>STEP 3 — COPY SSH KEY TO MANAGED NODE</h3><p>The SSH public key is copied to the remote server to allow automatic SSH login without entering passwords also run it on the control node server as well so the control node and the ssh server are sharing the same key.</p><h4>Command:</h4><pre>ssh-copy-id srhel@192.168.65.135<br>ssh-copy-id rhel-lab@192.168.65.134</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*lK6O2ENXwbEYe9H3CTok7g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/1*djXYH3pSbQNpRUOErlcTiA.png" /></figure><h4>Command Explanation:</h4><ul><li>ssh-copy-id copies the SSH public key to the remote server.</li><li>rhel-lab and srhel are remote usernames =</li><li>@ separates the username from the IP address.</li><li>192.168.65.134 and 192.168.65.135 are the IP address of the managed nodes.</li></ul><h3>STEP 4 — TEST SSH CONNECTION</h3><p>The SSH connection is tested to verify that passwordless login works successfully.</p><h4>Command:</h4><pre>ssh rhel-lab@192.168.65.134<br>ssh srhel@192.168.65.135</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*1l3ukWirH-Q6ZsaqMAB6MQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*4XU-0mfdS9tL-o4XLHGQgg.png" /></figure><h4>Verification Explanation:</h4><ul><li>ssh establishes a secure remote connection.</li></ul><p>If login occurs without repeatedly requesting passwords, passwordless authentication is working correctly.</p><h3>STEP 5 — CREATE INVENTORY FILE</h3><p>The inventory file stores the list of managed nodes that Ansible will manage.</p><p>The inventory file is created on the control node.</p><h4>Command:</h4><pre>sudo vim inventory</pre><h4>Command Explanation:</h4><ul><li>vim opens the Vim text editor.</li><li>inventory is the name of the inventory file being created.</li></ul><h4>INVENTORY FILE CONTENT:</h4><pre>[webservers]<br>192.168.65.134 ansible_user=rhel-lab<br>192.168.65.135 ansible_user=srhel</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/1*qRxqt8XWkvHr2dmcgp_BFw.png" /></figure><h4>Inventory Explanation:</h4><ul><li>[webservers] creates a group called webservers.</li><li>192.168.65.134 is the first managed server.</li><li>ansible_user=rhel-lab tells Ansible to connect to that server using the <strong>rhel-lab</strong> account.</li><li>192.168.65.135is the second managed server.</li><li>ansible_user=srhel tells Ansible to connect to that server using the <strong>srhel</strong> account.</li></ul><h4>Why We Added ansible_user:</h4><p>The two managed nodes use different usernames:</p><ul><li>Server 1 → rhel-lab</li><li>Server 2 → srhel</li></ul><p>By specifying ansible_user, Ansible automatically uses the correct username for each server during SSH connections, ensuring successful communication with both managed nodes.</p><h3>STEP 6 — CONFIGURE PASSWORDLESS SUDO</h3><p>The playbook uses become: yes to perform administrative tasks such as installing packages, managing services, and modifying system files.</p><p>To allow Ansible execute these tasks automatically on the managed nodes without requesting a password, passwordless sudo must be configured.</p><h4>Command:</h4><p>sudo visudo</p><h4>Command Explanation:</h4><ul><li>sudo - executes the command with administrative privileges.</li><li>visudo - safely edits the sudoers configuration file.</li></ul><p>i - to insert into the visudo file</p><h4>Add the Following Entry:</h4><pre>rhel-lab ALL=(ALL) NOPASSWD: ALL</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*tyKXOLtp4-hWMW9h2S4c0A.png" /></figure><h4>Explanation:</h4><ul><li>rhel-lab identifies the user.</li><li>ALL=(ALL) allows the user to run commands as any user.</li><li>NOPASSWD disables sudo password prompts.</li><li>ALL grants access to all commands.</li></ul><p>To save and exit use the esc key then type :wq then press enter</p><h4>Passwordless configuration on the managed node</h4><p>On the control node SSH into the managed node to insert the passwordless configuration</p><p><strong>To SSH:</strong></p><p>ssh srhel@192.168.65.135— Connects to the second managed node.</p><p><strong>Command to open the configuration file: </strong>sudo visudo</p><p><strong>Command Explanation:</strong> Opens the sudoers file safely for editing.</p><ul><li>Scroll to the bottom of the file using your arrow keys.</li><li>Locate the <strong>User Rules section</strong>. You are looking for lines that start with the %wheel group or standard user aliases.</li><li>Press <strong>Enter </strong>to add the Following Entry:</li></ul><pre>srhel ALL=(ALL) NOPASSWD: ALL</pre><h4>Explanation:</h4><ul><li>Grants passwordless sudo access to the srhel user.</li></ul><p><strong>Verification Command: </strong>sudo -l</p><p><strong>Command Explanation: </strong>Displays the sudo privileges assigned to the current user.</p><h4>Verification Explanation:</h4><p>The output should show that the user can execute commands without being prompted for a password.</p><h3>STEP 7 — INSTALL REQUIRED ANSIBLE COLLECTION</h3><p>The playbook uses the ansible.posix.firewalld module to manage firewall rules.</p><p>Before creating the playbook, the required Ansible collection should be installed on the control node.</p><h4>Command:</h4><p>ansible-galaxy collection install ansible.posix</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zvnbtzv8P29_WFHzi-0Lmw.png" /></figure><h4>Command Explanation:</h4><ul><li>ansible-galaxy manages Ansible roles and collections.</li><li>collection specifies collection management.</li><li>install downloads and installs a collection.</li><li>ansible.posix contains the firewalld module used in this practical.</li></ul><h4>Verification Command:</h4><p>ansible-galaxy collection list</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*Oe6izl1g-zR0N8B-lkrPhA.png" /></figure><h4>Command Explanation:</h4><ul><li>Displays all installed Ansible collections.</li></ul><h4>Verification Explanation:</h4><p>The output should contain:</p><p>ansible.posix</p><p>confirming successful installation.</p><h3>STEP 8 — TEST ANSIBLE CONNECTIVITY</h3><p>Before automation begins, connectivity between the control node and managed nodes must be verified.</p><h4>Command:</h4><pre>ansible -i inventory webservers -m ping</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*4Oz0kmfZa9w6lFqDKnD99Q.png" /></figure><h4>Command Explanation:</h4><ul><li>ansible runs an Ansible command.</li><li>-i inventory specifies the inventory file to use.</li><li>webservers targets the webservers group.</li><li>-m ping uses the ping module to test connectivity.</li></ul><h4>EXPECTED OUTPUT:</h4><pre>SUCCESS =&gt; pong</pre><p>This output confirms successful communication between the control node and managed nodes.</p><h3>STEP 9 — CREATE PLAYBOOK FILE</h3><p>A playbook file is created to store all automation tasks in YAML format.</p><p>The playbook is containing the automation tasks that Ansible will execute on the managed nodes.</p><h4>Command:</h4><pre>vim web_setup.yml</pre><h4>Command Explanation:</h4><ul><li>vim opens the Vim text editor.</li><li>web_setup.yml is the playbook file being created.</li></ul><h3>PLAYBOOK SCRIPT</h3><pre>- name: Deploy Apache Web Server with Firewall Configuration<br>  hosts: webservers<br>  become: yes  <br>  tasks:   <br><br>- name: Install Apache web server<br>  dnf:<br>    name: httpd<br>    state: present<br><br>- name: Start and enable Apache<br>  service:<br>    name: httpd<br>    state: started<br>    enabled: yes<br><br>- name: Install firewalld<br>  dnf:<br>    name: firewalld<br>    state: present<br><br>- name: Start firewalld<br>  service:<br>    name: firewalld<br>    state: started<br>    enabled: yes<br><br>- name: Allow HTTP service through firewall<br>  ansible.posix.firewalld:<br>    service: http<br>    permanent: yes<br>    state: enabled<br>    immediate: yes<br><br>- name: Create custom index page<br>    copy:<br>    dest: /var/www/html/index.html<br>     content:|<br>     &lt;html&gt;<br>      &lt;head&gt;&lt;title&gt;My Ansible Web Server&lt;/title&gt;&lt;/head&gt;<br>       &lt;body&gt;<br>        &lt;h1&gt;Apache deployed using Ansible on RHEL 10 &lt;/h1&gt;<br>         &lt;/body&gt;<br>          &lt;/html&gt;</pre><h4>PLAYBOOK TASK EXPLANATION:</h4><h4>Apache Installation Task:</h4><pre>dnf:<br>  name: httpd<br>  state: present</pre><h4>Explanation:</h4><ul><li>dnf is the Ansible module used to install software packages.</li><li>name: httpd specifies the Apache package name.</li><li>state: present ensures the package is installed.</li></ul><h4>Start Apache Service:</h4><pre>service:<br>  name: httpd<br>  state: started<br>  enabled: yes</pre><h4>Explanation:</h4><ul><li>service manages Linux services.</li><li>name: httpd specifies the Apache service.</li><li>state: started ensures the service is currently running.</li><li>enabled: yes ensures the service starts automatically after reboot.</li></ul><h4>Install Firewall Service:</h4><pre>dnf:<br>  name: firewalld<br>  state: present</pre><h4>Explanation:</h4><ul><li>dnf installs software packages.</li><li>name: firewalld specifies the firewall package name.</li><li>state: present ensures the package is installed.</li></ul><h4>Start Firewall Service:</h4><pre>service:<br>  name: firewalld<br>  state: started<br>  enabled: yes</pre><h4>Explanation:</h4><ul><li>service controls Linux services.</li><li>name: firewalld specifies the firewall service.</li><li>state: started ensures the firewall service is running.</li><li>enabled: yes starts the firewall automatically after reboot.</li></ul><h4>Open HTTP Port in Firewall:</h4><pre>firewalld:<br>  service: http<br>  permanent: yes<br>  state: enabled<br>  immediate: yes</pre><h4>Explanation:</h4><ul><li>firewalld is the Ansible module used for firewall configuration.</li><li>service: http allows HTTP traffic through port 80.</li><li>permanent: yes keeps the firewall rule after reboot.</li><li>state: enabled activates the firewall rule.</li><li>immediate: yes applies the firewall rule instantly.</li></ul><h4>Create Custom Webpage:</h4><pre>copy:<br>  dest: /var/www/html/index.html</pre><h4>Explanation:</h4><ul><li>copy transfers files or content to remote systems.</li><li>dest specifies the destination location of the webpage file.</li></ul><h3>STEP 10 — RUN PLAYBOOK</h3><p>The playbook is executed so all configurations can be applied automatically on the managed nodes.</p><h4>Command:</h4><pre>ansible-playbook -i inventory web_setup.yml</pre><h4>Command Explanation:</h4><ul><li>ansible-playbook runs Ansible playbook files.</li><li>i inventory specifies the inventory file.</li><li>web_setup.yml is the playbook file being executed.</li></ul><h3>STEP 11 — VERIFY APACHE SERVICE</h3><p>The Apache service status is checked to verify successful deployment.</p><h4>Command:</h4><pre>systemctl status httpd</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EzMsK9d5LJrSRTPsONMABQ.png" /></figure><h4>Command Explanation:</h4><ul><li>systemctl manages Linux services.</li><li>status checks the current service state.</li><li>httpd is the Apache web server service.</li></ul><h3>STEP 12 — VERIFY THE WEB PAGE</h3><p>The custom web page deployed by Ansible should be tested.</p><h4>Commands to run on each nodes:</h4><pre>curl &lt;http://192.168.65.134&gt;</pre><pre>curl &lt;http://192.168.65.135&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*SXDmxRn3GXQEeZ5wwsK9vg.png" /></figure><h4>Command Explanation:</h4><ul><li>curl – Retrieves data from a web server.</li><li>http://192.168.65.134 ****– The target web server.</li></ul><h4>Verification:</h4><p>Expected output:</p><pre>&lt;h1&gt;Apache deployed using Ansible on RHEL 10&lt;/h1&gt;</pre><h4>Verification Explanation:</h4><p>Confirms that the web page was successfully deployed.</p><h3>VERIFY THROUGH WEB BROWSER</h3><h4>URL:</h4><pre>&lt;http://192.168.65.135&gt;<br>&lt;http://192.168.65.134&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3mSHbPpLK7emYuSCY5U9gA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jSJivbMetWSiAQokUOABUQ.png" /></figure><h4>Verification Explanation:</h4><p>Opening the server IP address in a browser confirms that the Apache web server is working successfully.</p><h4>CONCLUSION</h4><p>In this practical, Ansible was successfully installed and configured on a RHEL 10 control node. SSH key-based authentication was configured to allow secure communication between the control node and managed nodes.</p><p>An inventory file was created to define the managed servers, and an Ansible playbook was developed to automate Apache installation, firewall configuration, and webpage deployment.</p><p>The automation process reduced manual configuration effort and demonstrated how Ansible simplifies system administration through Infrastructure as Code (IaC).</p><h4>FINAL OUTCOME:</h4><p>✔ Ansible installed successfully</p><p>✔ SSH key authentication configured</p><p>✔ Inventory file created successfully</p><p>✔ Apache web server installed automatically</p><p>✔ Firewall configured automatically</p><p>✔ HTTP access enabled</p><p>✔ Custom webpage deployed successfully</p><p>✔ Full automation achieved using Ansible</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9f31b7fc811" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes Cluster Configuration and Nginx Web Application Deployment]]></title>
            <link>https://medium.com/@bamidelebabatundem/kubernetes-cluster-configuration-and-nginx-web-application-deployment-d330c498990a?source=rss-99476dec8c94------2</link>
            <guid isPermaLink="false">https://medium.com/p/d330c498990a</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[kubelet]]></category>
            <category><![CDATA[rhel]]></category>
            <dc:creator><![CDATA[Babatunde]]></dc:creator>
            <pubDate>Thu, 21 May 2026 14:50:16 GMT</pubDate>
            <atom:updated>2026-05-21T14:50:16.902Z</atom:updated>
            <content:encoded><![CDATA[<h4>Objective</h4><p>To install and configure Kubernetes, deploy a containerized application (NGINX), and manage it using core components such as Pods, Deployments, and Services.</p><h4>What is Kubernet?</h4><p><strong>Kubernetes</strong> is an open-source platform used to <strong>automatically deploy, manage, scale, and monitor containerized applications</strong> across multiple systems.</p><h4>What is Kubernetes Used For?</h4><p><strong>Kubernetes</strong> is used to <strong>automatically manage, deploy, scale, and monitor containerized applications</strong>.</p><h4>In simple terms:</h4><ul><li>Docker → runs containers</li><li>Kubernetes → <strong>controls many containers across systems</strong></li></ul><h4>What it helps you do:</h4><ul><li>Deploy applications easily</li><li>Scale up/down automatically</li><li>Restart failed containers (self-healing)</li><li>Manage multiple containers in one system</li></ul><h4>Practical Task Performed</h4><p>In this practical:</p><ul><li>Kubernetes was installed and configured</li><li>System issues affecting Kubernetes were resolved</li><li>A Kubernetes cluster was initialized</li><li>Networking was configured using Flannel</li><li>An Nginx application was deployed</li><li>The application was exposed using a Kubernetes Service</li></ul><h3>Step 1: Disable Swap Memory</h3><h4>What is Swap?</h4><p>Swap is a portion of disk space used as additional memory when physical RAM becomes full.</p><p>Kubernetes recommends disabling swap to ensure proper memory and resource management.</p><h4>Command</h4><pre>sudo swapoff -a</pre><h4>Command Explanation</h4><ul><li>swapoff → disables swap memory</li><li>a → disables all active swap partitions</li></ul><h4>Make it permanent (VERY IMPORTANT)</h4><pre>sudo sed -i &#39;/ swap / s/^/#/&#39; /etc/fstab</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sKo7I7yvyrlAf9JbdDnvEA.png" /></figure><h4>Explanation:</h4><ul><li>Finds swap entry in system config /etc/fstab</li><li>Comments it out</li><li>Prevents swap from coming back after reboot</li></ul><h4>Purpose</h4><p>Disables swap memory to allow Kubernetes services to function properly.</p><h3>Step 2: Add Kubernetes Repository</h3><p>The Kubernetes repository must be added because the required packages are not available in the default RHEL repositories. Adding the repository allows the package manager to locate and install Kubernetes components from an external source.</p><h4>1. Create repo file</h4><pre>sudo vim /etc/yum.repos.d/kubernetes.repo</pre><h4>2: Add this content</h4><pre>[kubernetes]<br>name=Kubernetes<br>baseurl=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/<br>enabled=1<br>gpgcheck=1<br>gpgkey=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/repodata/repomd.xml.key</pre><h4>3: Save and exit</h4><p>In vim:</p><pre>ESC<br>:wq</pre><h3>Step 3: Install Kubernetes Tools</h3><h4>Command to install kubernetes tools</h4><pre>sudo dnf install -y kubelet kubeadm kubectl</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RfIFo_0JsN8Rhc2pVuxT-A.png" /></figure><h4>Explanation:</h4><ul><li>sudo → Runs command with administrative privileges</li><li>dnf install → Installs packages</li><li>kubelet → Runs containers on each node</li><li>kubeadm → Initializes Kubernetes cluster</li><li>kubectl → CLI tool to manage Kubernetes</li></ul><h3>Step 4: Start kubelet Service</h3><pre>sudo systemctl enable --now kubelet</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S2jkFvOT9iKtqQTRL_bdpg.png" /></figure><h4>Explanation:</h4><ul><li>systemctl → Manages system services</li><li>enable → Starts service at boot</li><li>-now → Starts service immediately</li><li>kubelet → Kubernetes node agent</li></ul><h4>Output:</h4><pre>Created symlink &#39;/etc/systemd/system/multi-user.target.wants/kubelet.service&#39; → &#39;/usr/lib/systemd/system/kubelet.service&#39;.</pre><h4>Meaning:</h4><ul><li>A <strong>symbolic link (shortcut)</strong> was created</li><li>This ensures kubelet <strong>starts automatically when the system boots</strong></li></ul><h4>Check kubelet status</h4><pre>sudo systemctl status kubelet</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-SF2whJHYRji1tIhaw22pQ.png" /></figure><h4>Explanation:</h4><ul><li>status → Displays the current state of the service</li></ul><h3>Step 5: Configure Kubernetes Networking</h3><p>Kubernetes networking configuration allows communication between Pods, Services, and cluster components.</p><p>This configuration enables Kubernetes to properly manage network traffic, packet forwarding, and communication between containerized applications running inside the cluster.</p><p>It also ensures that network plugins such as Flannel can function correctly within the Kubernetes environment.</p><h4>Command</h4><pre>sudo modprobe br_netfilter</pre><h4>Command Explanation</h4><ul><li>modprobe → loads kernel modules</li><li>br_netfilter → enables bridge network filtering</li></ul><h3>Verifying Kubernetes Network Module Configuration</h3><p>After loading the br_netfilter module, the bridge networking files were verified to confirm that Kubernetes networking support was successfully enabled.</p><h4>Verification Command</h4><pre>ls /proc/sys/net/bridge</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RVKbO6TPIcWc1WTfTUSlig.png" /></figure><h4>Command Explanation</h4><ul><li>ls → lists directory contents</li><li>/proc/sys/net/bridge → directory containing bridge networking parameters</li></ul><h4>Result</h4><pre>bridge-nf-call-arptables<br>bridge-nf-call-iptables<br>bridge-nf-call-ip6tables</pre><h4>Meaning</h4><p>The presence of these files confirms that:</p><ul><li>the br_netfilter module loaded successfully</li><li>Kubernetes networking support is active</li><li>bridge traffic filtering is available for Pod communication</li></ul><h4>Reason</h4><p>Kubernetes requires bridge network filtering to allow proper communication and traffic management between Pods and Services within the cluster.</p><h3>Step 6: Configure Packet Forwarding</h3><h4>Command</h4><pre>echo &quot;net.bridge.bridge-nf-call-iptables = 1&quot; | sudotee -a /etc/sysctl.conf</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cd2S_u4vQOq4f7jFpsFlJA.png" /></figure><h4>Command Explanation</h4><ul><li>echo → prints configuration</li><li>net.bridge.bridge-nf-call-iptables = 1 → enables packet filtering</li><li>tee -a → appends output to file</li></ul><p>Enables Kubernetes networking rules for Pod communication.</p><h3>Step 7: Reload System Configuration</h3><p>After modifying Kubernetes networking settings, the system configuration must be reloaded so the new settings can take effect immediately.</p><p>This step applies the updated kernel and network parameters without requiring a system reboot.</p><h4>Command</h4><pre>sudo sysctl -p</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*vGojEWCMoHvZftsQSHKxpA.png" /></figure><h4>Command Explanation</h4><ul><li>sysctl → manages kernel settings</li><li>-p → reload configuration file</li></ul><p>Applies networking changes without rebooting.</p><h3>Step 8: Pull Kubernetes Images</h3><p>Before initializing the Kubernetes cluster, the required Kubernetes container images were downloaded to the system.</p><p>These images contain the core Kubernetes components needed to create and run the control plane services.</p><h4>Command</h4><pre>sudo kubeadm config images pull</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Ex9ixbVb8Rnu-5iW5ZZI6g.gif" /></figure><h4>Command Explanation</h4><ul><li>sudo → runs the command with administrator privileges</li><li>kubeadm → Kubernetes cluster initialization tool</li><li>config → manages Kubernetes configuration settings</li><li>images → refers to Kubernetes container images</li><li>pull → downloads the required images to the system</li></ul><p>Ensures required system components are ready before cluster initialization.</p><h3>Step 9: Kubernetes Cluster Initialization</h3><p>To initialize a Kubernetes cluster using kubeadm and prepare the control plane for deploying and managing containerized applications.</p><pre>sudo kubeadm init</pre><h4>Explanation:</h4><ul><li>kubeadm → Kubernetes setup tool</li><li>init → initializes the Kubernetes control plane</li></ul><p>This command is used to:</p><ul><li>Create the Kubernetes cluster</li><li>Set up control plane components (API server, scheduler, controller manager)</li><li>Prepare the system for running workloads</li></ul><h4>Modified Command (Used in This Lab)</h4><pre>sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=Mem</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*IcPWmj5xmmymJNmjXPQY7Q.gif" /></figure><h4>Explanation:</h4><ul><li>--pod-network-cidr=10.244.0.0/16 → assigns the Pod network range required by Flannel</li><li>--ignore-preflight-errors=Mem → tells Kubernetes to ignore the minimum memory requirement</li></ul><p>This command performs the <strong>same function</strong> as the standard command but:</p><ul><li>Bypasses the RAM check</li><li>Allows initialization on low-memory systems</li></ul><h4>Why Both Commands Were Used</h4><h4>1. Why the Standard Command is Important</h4><p>The standard kubeadm init command represents the <strong>correct and recommended way</strong> to initialize a Kubernetes cluster under normal system conditions.</p><p>It ensures:</p><ul><li>All system requirements are met</li><li>The cluster is stable and production-ready</li></ul><h4>2. Why the Modified Command Was Used</h4><p>In this practical:</p><ul><li>The system had <strong>insufficient RAM (~1.6GB)</strong></li><li>Kubernetes required at least <strong>~1.7GB</strong></li></ul><p>Because of this:</p><ul><li>The standard command failed</li><li>The memory check blocked initialization</li></ul><p>Solution:</p><ul><li>Use -ignore-preflight-errors=Mem to bypass the restriction</li></ul><h4>Summary</h4><p>The Kubernetes cluster was initialized using the kubeadm init command. However, due to limited system memory in the lab environment, the command was executed with the --ignore-preflight-errors=Mem flag to bypass the minimum memory requirement. Both commands perform the same function, with the latter allowing the initialization process to proceed despite system constraints.</p><h3>Step 10: Configure kubectl Access</h3><h4>Create directory</h4><pre>mkdir -p $HOME/.kube</pre><h4>Explanation:</h4><ul><li>mkdir → Create directory</li><li>p → Create parent directories if they don’t exist</li><li>$HOME → Current user’s home directory</li></ul><h4>Copy configuration file</h4><pre>sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config</pre><h4>Explanation:</h4><ul><li>cp → Copy file</li><li>i → Prompt before overwrite</li><li>admin.conf → Cluster admin configuration</li></ul><h4>Set permissions</h4><pre>sudo chown $(id -u):$(id -g) $HOME/.kube/config</pre><h4>Explanation:</h4><ul><li>chown → Change file ownership</li><li>$(id -u) → Current user ID</li><li>$(id -g) → Current group ID</li><li>: → Separates user and group</li></ul><h3>Step 11: Install Network Plugin</h3><p>To deploy Flannel CNI plugin into Kubernetes</p><pre>kubectl apply -f &lt;https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iVmOz2DwbjeJaFc863z8PA.png" /></figure><h4>Command Explanation:</h4><ul><li>kubectl → Kubernetes CLI</li><li>apply → Creates or updates resources</li><li>-f → Specifies file or URL</li></ul><p>Installs Flannel network for Pod communication.</p><p>Enables Pod-to-Pod networking inside the cluster.</p><h3>Step 12: Verify Cluster Status</h3><p>Command to display all nodes in the cluster.:</p><pre>kubectl get nodes</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*9ybV_FAFJ3QS7ckX0jLPrQ.png" /></figure><h4>Explanation:</h4><ul><li>get → Retrieve resources</li><li>nodes → Machines in the cluster</li></ul><p>This command verifies that the Kubernetes node is active and in a Ready state before deploying applications.</p><h3>Step 13: Deploy Nginx Application</h3><p>After successfully configuring the Kubernetes cluster, an application was needed to test and demonstrate how Kubernetes manages containerized workloads.</p><p>A <strong>Deployment</strong> is a Kubernetes object used to <strong>create, manage, and maintain Pods automatically</strong>.</p><p>A Deployment is like a <strong>manager for Pods</strong>.</p><ul><li>Pod → runs your application</li><li>Deployment → <strong>controls and maintains Pods</strong></li></ul><h4>What a Deployment does:</h4><ul><li>Creates Pods</li><li>Ensures the <strong>desired number of Pods are running</strong></li><li>Automatically <strong>restarts failed Pods</strong></li><li>Allows <strong>scaling</strong> (increase/decrease number of Pods)</li><li>Supports <strong>updates and rollbacks</strong></li></ul><h4>Command used:</h4><pre>kubectl create deployment nginx-deployment --image=nginx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*ZwpHjb8FXVNVYYQr0oEmRg.png" /></figure><h4>Command Explanation</h4><p>Creates a Deployment that runs Nginx containers.</p><h4>Purpose of Deploying the Nginx Application</h4><p>The Nginx application was deployed to demonstrate how Kubernetes manages and runs containerized applications within a cluster environment.</p><p>Nginx was selected because it is lightweight, widely used, and suitable for testing Kubernetes Deployments, Pods, and Services.</p><h3>Step 14: Expose Nginx Application</h3><p><strong>Expose deployment</strong> means creating a <strong>Service</strong> for a Deployment so that it can be <strong>accessed over the network.</strong></p><p>Without exposing, your app runs <strong>but cannot be accessed from outside</strong>.</p><h4>Command</h4><pre>kubectl expose deployment nginx-deployment--port=80--type=NodePort</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x7k_cRnBVvc4QRJ_OerU_A.png" /></figure><h4>Command Explanation</h4><ul><li>expose deployment → creates a Service</li><li>-port=80 → exposes container port</li><li>-type=NodePort → allows external access</li></ul><h4>Purpose of Exposing the Nginx Application</h4><p>The Nginx application was exposed to make the deployed web application accessible outside the Kubernetes cluster.</p><p>This demonstrates how Kubernetes Services provide external access and communication to containerized applications running inside Pods.</p><h4>Why we use it</h4><ul><li>To <strong>access the application in a browser</strong></li><li>To allow <strong>external communication</strong></li><li>To provide a <strong>stable IP/port</strong> (Pods change, Service stays constant)</li></ul><h3>Step 15: Deployment Verifications</h3><p>Verification commands were used to confirm that the Kubernetes resources were created and functioning correctly.</p><h4>1. Verify Deployments</h4><p>Deployments were verified to ensure the application was successfully deployed.</p><pre>kubectl get deployments</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*XkMbybF4xuUiIfcaunL7rA.png" /></figure><h4>Explanation:</h4><ul><li>Lists deployments</li><li>Shows replicas and availability</li></ul><h4>2. Verify Pods</h4><p>Pods were verified to confirm that the Nginx containers were running properly.</p><pre>kubectl get pods</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*9ZLIvkCvCXNXSTH4y2A5dg.png" /></figure><h4>Explanation:</h4><ul><li>Lists all Pods</li><li>Shows status (Running, Pending, etc.)</li></ul><h4>3. Verify Services</h4><p>Services were verified to ensure the application was successfully exposed and accessible within the cluster.</p><pre>kubectl get services</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*A9eQ-5WE9pFb3uP-CgYjEw.png" /></figure><h4>Explanation:</h4><ul><li>Lists services</li><li>Shows how apps are exposed</li></ul><h3>Step 16: Accessing the Nginx Application in a Browser</h3><p>After exposing the Deployment using a NodePort Service, the application can be accessed through the system IP address and assigned NodePort.</p><h3>Check Service Port</h3><p>Kubernetes automatically assigned a port from the NodePort range (usually 30000–32767)</p><h4>Command</h4><pre>kubectl get services</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ChoEpR8_LPcCkDMZGhTN_g.png" /></figure><h4>Purpose</h4><p>Displays the Service information including:</p><ul><li>Service name</li><li>Cluster IP</li><li>External port (NodePort)</li></ul><h4>Meaning</h4><ul><li>80 → container port</li><li>30728 → external NodePort assigned by Kubernetes</li></ul><p>The application can now be accessed through port 30728.</p><h3>Get System IP Address</h3><h4>Command</h4><pre>ip a</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OxRWhilWnPJEZVsr6o68ww.png" /></figure><h4>Purpose</h4><p>Displays the system network IP address.</p><h3>Access Application in Browser</h3><h4>Format</h4><pre>http://SYSTEM-IP:NODEPORT</pre><h4>Example</h4><pre>http://192.168.153.129:30728</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yI-3cbXw-N8brvqPdIyZfw.png" /></figure><h4>Result</h4><p>The default Nginx welcome page appears in the browser.</p><p>This confirms:</p><ul><li>Kubernetes networking is functioning</li><li>The Service is accessible externally</li><li>Communication between Kubernetes resources is working properly</li></ul><h3>Allow External Communication (Firewall Configuration)</h3><h4>Command</h4><pre>sudo firewall-cmd --permanent --add-port=30728/tcp</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*I3Kx_f8nU986qUN5PS8ELw.png" /></figure><h4>Explanation</h4><ul><li>firewall-cmd → manages firewall settings</li><li>-permanent → saves rule permanently</li><li>-add-port=30080/tcp → allows NodePort traffic</li></ul><h3>Reload Firewall</h3><h4>Command</h4><pre>sudo firewall-cmd --reload</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*CxK_m1-QQ-zMXyTEL6xSoQ.png" /></figure><h4>Purpose</h4><p>Applies the new firewall configuration.</p><h4>Purpose of Firewall Configuration</h4><p>Allows external systems and browsers to communicate with the Kubernetes NodePort Service.</p><h3><strong>Key Concepts</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*IFrkv6hQfLE-z8kUz1fnpg.png" /></figure><h3>Final Documentation Summary</h3><p>Kubernetes was successfully installed and configured, and containerized applications were deployed and managed using Pods, Deployments, and Services, demonstrating effective container orchestration and cluster management.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d330c498990a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker Practical: Custom Nginx Deployment and Automation]]></title>
            <link>https://medium.com/@bamidelebabatundem/docker-practical-custom-nginx-deployment-and-automation-2ab2476e4ede?source=rss-99476dec8c94------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ab2476e4ede</guid>
            <category><![CDATA[rhel-10]]></category>
            <category><![CDATA[docker-image]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[rhel]]></category>
            <category><![CDATA[dockerfiles]]></category>
            <dc:creator><![CDATA[Babatunde]]></dc:creator>
            <pubDate>Mon, 13 Apr 2026 11:11:14 GMT</pubDate>
            <atom:updated>2026-09-30T11:28:23.527Z</atom:updated>
            <content:encoded><![CDATA[<h3>Objective</h3><p>To install and configure Docker, deploy and manage containerized applications, and implement basic automation for efficient and consistent service delivery.</p><h3>User Privileges:</h3><p>All tasks were performed using the root user to allow full administrative control during Docker installation and configuration.</p><h3>Root User Access</h3><p>Switched to the root user to perform administrative tasks with full privileges.</p><h4>Command used</h4><pre>su -</pre><h4>Explanation</h4><ul><li>su → Switch user</li><li>→ Loads root’s full environment (recommended)</li><li>You will be prompted to enter the <strong>root password</strong></li></ul><p>This gives unrestricted access to the system for installation and configuration tasks.</p><h4>Alternative Method (if using sudo)</h4><pre>sudo -i</pre><h4>Explanation</h4><ul><li>Grants a root shell using sudo privileges</li><li>Works if your user is in the sudoers group</li></ul><h3>1. What is Docker?</h3><p>Docker is a containerization platform that allows you to package applications and their dependencies into lightweight, portable containers that run consistently across environments.</p><h3>2. Adding Docker Repository</h3><p>Added Docker’s official repository to the system.</p><pre>sudo dnf config-manager --add-repo &lt;https://download.docker.com/linux/rhel/docker-ce.repo&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*YZuJpfQWydEpX3AKSAXI4g.gif" /></figure><h4>Explanation</h4><ul><li>Links your system to Docker’s official package source</li><li>Ensures you install <strong>latest and supported versions</strong></li></ul><p>Without this, you may get outdated or missing packages.</p><h3>3. Docker Engine Installation</h3><p>Installed the core Docker service that allows the system to run containers.</p><pre>sudo dnf install -y docker-ce docker-ce-cli containerd.io</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*sHjDCLeGKwHTPsE5k9-IZw.gif" /></figure><h4>Explanation</h4><ul><li>docker-ce → Main Docker engine (runs containers)</li><li>docker-ce-cli → Command-line tool to interact with Docker</li><li>containerd.io → Backend service that manages container lifecycle</li></ul><p>This is the <strong>main component</strong> — without it, Docker won’t work.</p><h3>4. DNF Plugins Core Installation</h3><p>Installed tools required to manage repositories.</p><pre>sudo dnf install -y dnf-plugins-core</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*7sT9DFkVTIMYE025wNCAyQ.png" /></figure><h4>Explanation</h4><ul><li>Provides dnf config-manager</li><li>Allows adding external repositories like Docker’s repo</li></ul><p>Needed to <strong>prepare the system for Docker installation</strong></p><h3>5. Starting &amp; Enabling Docker Service</h3><p>Activated Docker and ensured it runs automatically.</p><pre>sudo systemctl start docker<br>sudo systemctl enable docker<br>sudo systemctl status docker</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MEqm4n1c5nZXae4y1_spCQ.png" /></figure><h3>Explanation</h3><ul><li>start → Runs Docker immediately</li><li>enable → Starts Docker automatically on boot</li><li>status → Checks the current status of Docker Service</li></ul><p>Makes Docker <strong>available and persistent</strong></p><h3>Verify Installation</h3><pre>docker --version</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*LfQx7k5Rk8Wxbhd4X9J5JQ.png" /></figure><p>You can also is use:</p><pre>sudo docker run hello-world</pre><p>to <strong>verify that Docker is installed and working properly</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9sR0yx10tj3k3QS1tmGoWg.png" /></figure><h4>What it does</h4><ol><li>Docker checks if the <strong>hello-world image</strong> exists locally.</li><li>If not, it <strong>pulls it from Docker Hub</strong>.</li><li>Docker then <strong>creates a container</strong> from that image and runs it.</li><li>The container prints a <strong>test message</strong> and then exits.</li></ol><h4>Why it’s under “Verify Installation”</h4><ul><li>Ensures the <strong>Docker daemon is running</strong></li><li>Confirms your system can <strong>pull images and run containers</strong></li><li>Quick and safe way to check everything before doing real work</li></ul><h3>Alternative Method to install Docker on Linux (Quick Install Script)</h3><p>This command is a <strong>shortcut way to install Docker</strong> on Linux</p><pre>curl -fsSL &lt;https://get.docker.com&gt; | sh</pre><p>Faster</p><p>Not recommended for production (less control)</p><h3>Explanation</h3><ol><li><strong>curl -fsSL &lt;https://get.docker.com&gt;</strong></li></ol><ul><li>Downloads a shell script from Docker’s official site.</li><li>Flags:</li><li>f → fail silently on errors</li><li>s → silent mode (no progress)</li><li>S → show errors if they occur</li><li>L → follow redirects</li></ul><ol><li><strong>| sh </strong>Pipes the downloaded script directly to sh (the shell), which <strong>executes it</strong>.</li></ol><h3>What the script does</h3><ul><li>Detects your Linux distribution</li><li>Sets up Docker’s official repository</li><li>Installs <strong>Docker Engine, CLI, and containerd</strong></li><li>Starts and enables the Docker service</li></ul><h3>Security note</h3><ul><li>Running a script directly from the internet can be risky.</li><li>In labs or controlled environments, it’s fine.</li><li>For production, it’s safer to <strong>review the script</strong> before running it.</li></ul><h3>6. Basic Docker Commands (Core Sysadmin Skills)</h3><h4>Pull an Image</h4><pre>docker pull nginx</pre><p>is used to <strong>download the official Nginx image from Docker Hub</strong> to your local system.</p><ul><li>Wait for it to download and extract</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p85PuM0h31e8Y3vCGSXWWg.png" /></figure><h4>What it does</h4><ol><li>Checks <strong>if the image exists locally</strong>.</li><li>If not, <strong>downloads all layers</strong> of the Nginx image from Docker Hub.</li><li>Stores it in Docker’s local image cache so you can use it to run containers.</li></ol><h3>Run a Container</h3><pre>docker run -d -p 8080:80 --name mynginx nginx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*GlF9O7JhmZTOIk5_kDCcMg.png" /></figure><h4>Explanation</h4><ul><li>d → Run in background</li><li>p 8080:80 → Map port (host:container)</li><li>-name → Assign container name</li></ul><h4>What happens</h4><ol><li>Docker looks for the nginx image locally (pulls from Docker Hub if needed).</li><li>Creates a container with the name mynginx.</li><li>Starts the Nginx service inside the container.</li><li>Container runs in the background, ready to serve requests on port 8080.</li></ol><h3>List Containers</h3><pre>docker ps<br>docker ps -a</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wNmr_hIOLT-j7c4nX6FTuw.png" /></figure><h3>Difference between the commands</h3><h3>docker ps</h3><pre>docker ps</pre><p><strong>Shows only running containers.</strong></p><p>If a container is stopped or exited, it <strong>will not appear</strong> in this list.</p><h3>docker ps -a</h3><pre>docker ps -a</pre><p><strong>Shows all containers.</strong></p><p>This includes:</p><ul><li>Running containers</li><li>Stopped containers</li><li>Exited containers</li></ul><h4>Simple way to remember</h4><ul><li>docker ps → <strong>Active containers only</strong></li><li>docker ps -a → <strong>All containers</strong></li></ul><h4>Stop / Start Container</h4><pre>docker stop mynginx<br>docker start mynginx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*9PtP5Sh_h-2H6l5fhvyONA.png" /></figure><h4>Remove Container</h4><pre>docker rm mynginx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T39Ase88-ct1BbUxm3hljA.png" /></figure><h4>List Images</h4><pre>docker images</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*NHYSJbGzpbIgV8NakRoCFg.png" /></figure><h3>7. Working with Dockerfiles (Automation)</h3><h4>Create a Dockerfile</h4><p>The <strong>Dockerfile</strong> is used to <strong>build a custom Docker image</strong>.</p><p>Instead of manually configuring a container every time, the Dockerfile <strong>automates the process</strong> by defining the steps Docker should follow to create the image.</p><pre>vim Dockerfile</pre><h4>Insert:</h4><pre>FROM nginx:latest<br>COPY index.html /usr/share/nginx/html/</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/415/1*H3Yag0UGMjkCjkbW0fjigw.png" /></figure><p>What the <strong>Dockerfile</strong> specifically did</p><p>FROM nginx:latest</p><ul><li>Uses the <strong>Nginx image as the base</strong></li><li>This gives us a ready web server environment</li></ul><p>COPY index.html /usr/share/nginx/html/</p><ul><li>Copies our custom <strong>web page (</strong><strong>index.html)</strong></li><li>Places it in the Nginx web directory so it will be displayed when users access the server</li></ul><h4>What this achieves</h4><p>It creates a <strong>custom Nginx container that serves our own webpage instead of the default one</strong>.</p><p>The Dockerfile was created to automate the building of a custom Docker image by using the Nginx base image and adding a custom index.html file to serve a personalized web page.</p><h3>Build Image</h3><pre>docker build -t mycustomnginx .</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lv8h1-6qQAK8XF_vcGNdvQ.png" /></figure><h3>Run Custom Image</h3><pre>docker run -d -p 8081:80 mycustomnginx</pre><h4>Explanation</h4><ul><li>FROM → Base image</li><li>COPY → Add files into container</li><li>build → Creates image</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*1KjrXbJgY3Ul85pMVAJ6tg.png" /></figure><h3>8. Docker Volumes (Persistent Storage)</h3><h3>Create Volume</h3><pre>docker volume create mydata</pre><h4>Explanation</h4><ul><li>docker volume → Manages Docker storage volumes.</li><li>create → Creates a new volume.</li><li>mydata → The name assigned to the volume.</li></ul><h3>Use Volume</h3><pre>docker run -d -v mydata:/data nginx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*YgWKR4zxAAt18HjgbYTV7A.png" /></figure><h4>Why it is used</h4><p>Containers are <strong>temporary</strong>. When a container is removed, its data is normally lost.</p><p>A <strong>Docker volume</strong> allows data to <strong>persist outside the container</strong>, so it remains available even if the container is stopped or deleted.</p><h3>9. Docker Networking</h3><h3>Create Network</h3><pre>docker network create mynetwork</pre><h4>Explanation</h4><ul><li>docker network → Manages Docker networks.</li><li>create → Creates a new network.</li><li>mynetwork → The name of the network.</li></ul><h3>Run Container in Network</h3><pre>docker run -d --network=mynetwork --name web nginx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*ulZBmM5Nd6Y5gY58qrixjw.png" /></figure><h4>Why it is used</h4><p>A Docker network allows <strong>containers to communicate with each other securely</strong>.</p><p>Containers connected to the same network can:</p><ul><li>Reach each other using <strong>container names</strong></li><li>Exchange data internally without exposing ports to the host</li></ul><h3>10. Docker Compose (Multi-Container Setup)</h3><p>The docker-compose.yml file is used to <strong>define and manage multiple containers in a single configuration file</strong>.</p><p>Instead of running long docker run commands manually, <strong>Docker Compose allows you to describe the container setup in a file and start everything with one command</strong>.</p><h4>Create docker-compose.yml</h4><p>Create the file using vim (or any editor):</p><pre>vim docker-compose.yml</pre><pre>services:<br>  web:<br>    image: nginx<br>    ports:<br>      - &quot;8080:80&quot;</pre><p><strong>This configuration tells Docker to:</strong></p><ol><li>Create a service called <strong>web</strong></li><li>Use the <strong>Nginx image</strong></li><li>Map <strong>host port 8080 → container port 80</strong></li></ol><h4>Script Explanation</h4><ul><li>services: → Defines your containers</li><li>web: → Name of the service</li><li>image: nginx → <strong>Uses the pre-built Nginx image from Docker Hub</strong></li><li>ports: &quot;8080:80&quot; → Maps host port 8080 → container port 80</li></ul><h3>Run Compose</h3><pre>docker compose up -d</pre><p><strong>Docker will automatically:</strong></p><ul><li>Pull the image if needed</li><li>Create the container</li><li>Configure the network</li><li>Start the service</li></ul><h4>Explanation</h4><ul><li>Defines multiple containers in one file</li><li>Easier for real-world apps</li></ul><p><strong>Check running containers:</strong></p><pre>docker ps</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MOyIMHSuxMkjmIGpNjtloQ.png" /></figure><h3>Open your browser at http://localhost:8080 to see your custom web page</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fc59fsjL7w_mm3_RCHUDNA.png" /></figure><h3>11. Writing a Simple Automation Script</h3><p>The deploy_nginx.sh script is used to <strong>automate the deployment of an Nginx container.</strong></p><p>Instead of manually running several Docker commands, the script performs the entire process automatically.</p><h3>Create Script: deploy_nginx.sh</h3><p>Create with → vim</p><pre>#!/bin/bash</pre><pre>echo &quot;Pulling nginx image...&quot;<br>docker pull nginx</pre><pre>echo &quot;Stopping old container...&quot;<br>docker stop mynginx 2&gt;/dev/null<br>docker rm mynginx 2&gt;/dev/null</pre><pre>echo &quot;Starting new container...&quot;<br>docker run -d -p 8080:80 --name mynginx nginx</pre><pre>echo &quot;Deployment complete!&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*k3DYYMqLOSTQj7wi-uy3Ng.png" /></figure><h4>What this script does</h4><pre>#!/bin/bash</pre><ul><li>Shebang line → tells the system to execute the script using Bash.</li></ul><pre>echo &quot;Pulling nginx image...&quot;<br>docker pull nginx</pre><ul><li>Prints a message</li><li>Pulls the latest <strong>official Nginx image</strong> from Docker Hub</li></ul><pre>echo &quot;Stopping old container...&quot;<br>docker stop mynginx2&gt;/dev/null<br>docker rm mynginx2&gt;/dev/null</pre><ul><li>Stops any existing container named mynginx</li><li>Removes it</li><li>2&gt;/dev/null → hides errors if the container doesn’t exist (prevents noisy output)</li></ul><pre>echo &quot;Starting new container...&quot;<br>docker run -d -p 8082:80 --name mynginx nginx</pre><ul><li>Runs a <strong>new Nginx container</strong> in detached mode</li><li>Maps host port <strong>8082 → container port 80</strong></li><li>Names the container mynginx</li><li>We used 8082 because <strong>nginx is using 8080</strong>, <strong>mycustomnginx is using 8081</strong></li></ul><pre>echo &quot;Deployment complete!&quot;</pre><ul><li>Prints a final confirmation message</li></ul><h3>Why this is useful</h3><ul><li>Automates <strong>pulling, stopping old, and running new containers</strong></li><li>Saves you from typing multiple Docker commands manually</li><li>Perfect for lab documentation as a <strong>real-world deployment example</strong></li></ul><h3>Note:</h3><p>This Bash script automates the deployment of an Nginx container by pulling the latest image, stopping and removing any existing container named mynginx, running a new container on port 8082, and providing progress messages for clarity.</p><h3>Run Script</h3><pre>chmod +x deploy_nginx.sh<br>./deploy_nginx.sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XDzQBVfu-o0iarlSGmOELA.png" /></figure><h4>Explanation</h4><ul><li>Automates deployment</li><li>Handles errors silently (2&gt;/dev/null)</li><li>Good for sysadmin tasks</li></ul><p><strong>Docker Practical Completed</strong></p><p>Successfully installed Docker, deployed containers, created custom images using Dockerfiles, and automated deployment with scripts. Also explored container networking, storage, and multi-container management using Docker Compose.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ab2476e4ede" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[BACKUP & DISASTER RECOVERY IMPLEMENTATION (RHEL)]]></title>
            <link>https://medium.com/@bamidelebabatundem/backup-disaster-recovery-implementation-rhel-4e98c7706d98?source=rss-99476dec8c94------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e98c7706d98</guid>
            <category><![CDATA[script]]></category>
            <category><![CDATA[rhel]]></category>
            <category><![CDATA[disaster-recovery]]></category>
            <category><![CDATA[backup]]></category>
            <category><![CDATA[ssh]]></category>
            <dc:creator><![CDATA[Babatunde]]></dc:creator>
            <pubDate>Fri, 27 Mar 2026 14:33:59 GMT</pubDate>
            <atom:updated>2026-09-30T11:26:41.479Z</atom:updated>
            <content:encoded><![CDATA[<h3>Objective</h3><p>The task is to implement a backup and disaster recovery setup between two RHEL servers, ensuring data can be protected and restored when needed.</p><p><strong>To configure:</strong></p><ul><li>Backup of <strong>Server 1 → Server 2</strong></li><li>Automatic synchronization of changes</li></ul><p><em>You will need Administrator Priviledge as well — so login as root using </em>sudo -i<em> and put the root Password</em></p><h4>Environment</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*OUHWJQlQfRQ0niyVnahM2Q.png" /></figure><h3>STEP 1: Create Backup Directory (VERY IMPORTANT)</h3><p>On <strong>Server 2</strong>:</p><p>Login as root to make work easier</p><p>sudo -i</p><p>Put root user password</p><pre>mkdir -p /backup/home</pre><h4>Explanation:</h4><ul><li>mkdir → creates directory</li><li>p → creates parent directories if needed</li></ul><h4>Set Ownership</h4><pre>chown rhel-lab:rhel-lab /backup/home</pre><p>Ensures rsync can write into the directory</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*I3Ip7k7ooqMnHJK9Mz5QtQ.png" /></figure><h3>STEP 2: Configure Passwordless SSH</h3><p>On <strong>Server 1</strong>:</p><pre>ssh-keygen -t rsa</pre><ul><li>Press Enter for all prompts.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zni6ROiwVGUlP1hDpUJkmQ.png" /></figure><p>We skipped passphrase by pressing Enter:</p><p>So the key has <strong>no password</strong></p><h4>Why?</h4><ul><li>Needed for <strong>automation (cron jobs)</strong></li><li>rsync runs without asking for input</li><li>Backup runs <strong>silently in background</strong></li></ul><p><strong>Summary: </strong>We pressed Enter to use default settings and avoid a passphrase, allowing passwordless and automated SSH communication required for scheduled backups.</p><p><strong>Copy key to Server 2:</strong></p><pre>ssh-copy-id srhel@192.168.153.131</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a2OQRun0hWZM5aMFwA_7Hg.png" /></figure><p>The SSH key was copied to Server 2 to enable passwordless login from Server 1, allowing automated backups to run without manual password input.</p><h4>How Authentication Works</h4><p>When Server 1 connects to Server 2:</p><ol><li>Server 1 presents its SSH key</li><li>Server 2 checks if the key exists in the authorized_keys file</li><li>If the key is found, access is granted</li><li>No password is required</li></ol><p><strong>Test:</strong></p><pre>ssh srhel@192.168.153.131</pre><p>Should login without password</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Agf-u-603WBMBqVoFbLvA.png" /></figure><h3>STEP 3: Perform Initial Backup</h3><pre>rsync -avz /home/ srhel@192.168.153.131:/backup/home/</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*RBJeFLuu0G4DuwuYSjFleQ.gif" /></figure><p>The rsync command is used to synchronize the contents of the /home directory from the primary server to the backup server while preserving file attributes and ensuring efficient data transfer.</p><h3>Command Breakdown</h3><p>It copies <strong>all contents inside </strong><strong>/home/ (Server 1) t</strong>o <strong>/backup/home/ (Server 2)</strong></p><ul><li>a → archive mode (permissions, ownership, timestamps)</li><li>v → verbose output</li><li>z → compression during transfer</li><li>/home/ → copies <strong>contents of home</strong></li><li>/backup/home/ → stores them neatly in backup</li></ul><p>The trailing slash (/) at the end of the source directory in the rsync command ensures that only the contents of the directory are copied, rather than the directory itself. This prevents the creation of a nested structure such as /home/home during backup or restoration.</p><h3>STEP 4: Create Backup Script</h3><pre>vim /usr/local/bin/backup.sh</pre><p>Paste:</p><pre>#!/bin/bash<br><br>SOURCE=&quot;/home/&quot;<br>DEST=&quot;srhel@192.168.153.131:/backup/home&quot;<br>LOG=&quot;/var/log/backup.log&quot;<br><br>echo &quot;Backup started at $(date)&quot; &gt;&gt; $LOG<br><br>rsync -az --delete $SOURCE $DEST &gt;&gt; $LOG 2&gt;&amp;1<br><br>echo &quot;Backup completed at $(date)&quot; &gt;&gt; $LOG</pre><h3>Script Explanation</h3><ul><li>SOURCE → directory to back up</li><li>DEST → backup server location</li><li>LOG → log file for monitoring</li><li>--delete tells rsync: → “If a file is removed from the source (Server 1), remove it from the destination (Server 2) too.”</li><li>&gt;&gt; $LOG → saves output</li><li>2&gt;&amp;1 → logs errors too</li></ul><h3>Make Script Executable</h3><pre>sudo chmod +x /usr/local/bin/backup.sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*eAcsPUL67TUUOTdWdmcLaQ.png" /></figure><h3>STEP 5: Automate with Cron</h3><pre>crontab -e</pre><p>Add:</p><pre>*/5 * * * * /usr/local/bin/backup.sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*R60DeWLpuHseCSQ0b5_rmQ.png" /></figure><h3>Explanation</h3><ul><li>Runs every <strong>5 minutes</strong></li><li>Keeps Server 2 always updated</li></ul><h3>STEP 6: Verify Backup</h3><pre>ls /backup/home</pre><p>On Server 2, confirm files exist</p><h3>How to Test backup.sh</h3><h3>1. Run the Script Manually (First Test)</h3><p>Instead of waiting for cron, run it yourself:</p><pre>/usr/local/bin/backup.sh</pre><p>If there’s any error, you’ll see it immediately</p><h3>2. Check the Log File</h3><pre>cat /var/log/backup.log</pre><p>or live:</p><pre>tail -f /var/log/backup.log</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mXh6wro1-5um8O2M5tanBw.png" /></figure><p>If errors happen, they’ll show here</p><ul><li>You can see the last roll <strong>Backup Completed</strong> with date and time</li></ul><h3>3. Verify Files on Server 2</h3><p>SSH into Server 2:</p><pre>ssh srhel@192.168.153.131</pre><p>Check:</p><pre>ls /backup/home</pre><p>Confirm files from /home exist</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DrePaf40Fk2pucyct0Io3A.png" /></figure><h3>4. Test File Sync (Very Important)</h3><p>On <strong>Server 1</strong>:</p><pre>touch /home/testfile.txt</pre><p>Run script again:</p><pre>/usr/local/bin/backup.sh</pre><p>Now check Server 2:</p><pre>ls /backup/home</pre><p>testfile.txt should appear</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ym1paXIcT7O9vKbI9VyY-g.png" /></figure><h3>5. Test --delete Behavior</h3><p>On <strong>Server 1</strong>:</p><pre>rm /home/testfile.txt</pre><p>Run script again:</p><pre>/usr/local/bin/backup.sh</pre><p>Check <strong>Server 2</strong>:</p><pre>ls /backup/home</pre><p>File should be gone</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*caq3TGs7x7pEimFR9-DWiw.png" /></figure><p>This confirms --delete is working</p><h3>Automated Backup Verification (Cron Test)</h3><p>To verify that the scheduled backup via cron works correctly:</p><ol><li>A test file was created on the primary server (Server 1):</li></ol><pre>touch /home/newtestfile.txt</pre><p>2. After the cron job ran (5 minutes later), the file appeared on the backup server (Server 2):</p><pre>ssh srhel@192.168.153.131<br>ls /backup/home/<br># newtestfile.txt appears</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L12T4siqUjB7T2k98dI1rw.png" /></figure><p>The test was repeated for deletion:</p><pre>rm /home/newtestfile.txt</pre><p>After the next cron run, the file was also removed from the backup server, confirming that rsync --delete mirrors changes from Server 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pfAO6iCmGaW7BgxA9U4p5Q.png" /></figure><p>This confirms that the automated backup and synchronization mechanism works as intended.</p><h3>STEP 7: DISASTER RECOVERY TEST</h3><p>This is the <strong>most important part.</strong></p><p><strong>Note:</strong> Before performing disaster recovery, the <strong>cron</strong> job was temporarily disabled to prevent automatic synchronization. This is important because the backup uses rsync --delete, which would replicate any deletion on the source server to the backup server. The /home directory was intentionally deleted to simulate a real-world failure scenario, allowing the recovery process to be tested. Disabling cron ensured the backup remained intact until restoration was completed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*ciUp8cTgUx7aw9FBrySXSg.png" /></figure><h3>Simulate Failure (Server 1)</h3><pre>rm -rf /home/*</pre><p>Deletes all user data (lab only!)</p><h3>Restore from Backup (Server 2 → Server 1)</h3><pre>rsync -avz srhel@192.168.153.131:/backup/home/ /home/</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*I6DcWCrNpLOvImiGZrfDZw.gif" /></figure><h3>Verify Recovery</h3><pre>ls /home</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*G-07OGCzRNfd4AhucUlzoA.png" /></figure><p>Files should be restored</p><h3>Key Concepts Learned</h3><ul><li>rsync performs <strong>incremental backups</strong></li><li>-delete ensures exact mirror</li><li>Cron enables <strong>automation</strong></li><li>SSH keys allow <strong>secure passwordless transfer</strong></li><li>Backup is useless without <strong>recovery testing</strong></li></ul><h3>Conclusion</h3><p>A reliable backup system was implemented using:</p><ul><li>rsync for data synchronization</li><li>cron for automation</li><li>SSH for secure communication</li></ul><p>This task implemented a backup and disaster recovery system using two RHEL servers. Automated backups with rsync and cron ensured that changes on the primary server are mirrored on the backup server. Disaster recovery was successfully tested, confirming that lost data can be restored reliably.</p><blockquote><em>“Backup without testing recovery is not a valid backup strategy.”</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e98c7706d98" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[System Update & Backup Automation]]></title>
            <link>https://medium.com/@bamidelebabatundem/automating-updates-backups-2b892fd08ee3?source=rss-99476dec8c94------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b892fd08ee3</guid>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[backup]]></category>
            <category><![CDATA[updates]]></category>
            <category><![CDATA[rhel]]></category>
            <category><![CDATA[bash-script]]></category>
            <dc:creator><![CDATA[Babatunde]]></dc:creator>
            <pubDate>Thu, 12 Mar 2026 15:35:06 GMT</pubDate>
            <atom:updated>2026-09-30T11:33:22.585Z</atom:updated>
            <content:encoded><![CDATA[<h3>Objective</h3><p>Learn how to automate system updates and file backups on <strong>Red Hat Enterprise Linux</strong> using <strong>GNU Bash</strong> scripting.</p><h3>1. Updating the System</h3><p>Keeping the system updated ensures security patches and software improvements are installed.</p><pre>sudo dnf update</pre><h4>Command Explanation</h4><p>dnf→ Package manager used to install and update software.</p><p>update→ Updates all installed packages to the latest available version.</p><h3>2. Automating System Updates with a Script</h3><p>Instead of running updates manually, we can automate it using a Bash script.</p><h4>Create the Script</h4><pre>vim update_system.sh</pre><h4>Script</h4><pre>#!/bin/bash<br><br>sudo dnf update -y</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*fklS9AdXF0-iEzYm1uAEzQ.png" /></figure><h4>Script Explanation</h4><p>#!/bin/bash→ Specifies the Bash interpreter.</p><p>dnf update -y→ Updates all packages automatically without asking for confirmation.</p><h4>Make the Script Executable</h4><pre>chmod +x update_system.sh</pre><h4>Run the Script</h4><pre>./update_system.sh</pre><h3>3. Creating a Backup Script</h3><p>Backups protect important data from loss or system failure.</p><h4>Create Script</h4><pre>vim backup.sh</pre><h4>Script</h4><pre>#!/bin/bash<br><br>sudo tar -czvf backup.tar.gz /home</pre><h4>Script Explanation</h4><p>sudo→ Administrator priviledge so it can backup from other users and also the root user</p><p>tar→ Archiving utility used to compress files.</p><p>c→ Creates a new archive.</p><p>z→ Compresses the archive using gzip.</p><p>v→ Shows progress of files being archived.</p><p>f→ Specifies the archive file name.</p><p>backup.tar.gz→ Name of the backup file.</p><p>/home→ Directory being backed up.</p><h3>4. Run the Backup Script</h3><pre>chmod +x backup.sh<br>./backup.sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*pPs7jbKFnsrnne_sZJl2FQ.gif" /></figure><p>This creates a compressed backup file of the <strong>/home directory</strong>.</p><h3>5. Verify the Backup</h3><pre>ls</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rF-xnm69PFQR1tmWBFXx9w.png" /></figure><ul><li><strong>backup.tar.gz</strong> highlighted in red</li></ul><p>This confirms the backup was created successfully.</p><p><strong>Day 17 Completed</strong></p><p>Bash scripting was used to automate system updates and create backups of important directories.</p><p>Skills practiced:</p><ul><li>System updates using dnf</li><li>Backup creation with tar</li><li>Bash scripting automation</li><li>Protecting system data with backups</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b892fd08ee3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[User Management Automation with Bash Scripting]]></title>
            <link>https://medium.com/@bamidelebabatundem/user-management-automation-with-bash-scripting-53c72307e047?source=rss-99476dec8c94------2</link>
            <guid isPermaLink="false">https://medium.com/p/53c72307e047</guid>
            <category><![CDATA[rhel]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[linux-tutorial]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[scripting]]></category>
            <dc:creator><![CDATA[Babatunde]]></dc:creator>
            <pubDate>Wed, 11 Mar 2026 15:11:36 GMT</pubDate>
            <atom:updated>2026-09-30T11:32:25.939Z</atom:updated>
            <content:encoded><![CDATA[<h3>Objective</h3><p>Learn how to automate Linux user creation in <strong>Red Hat Enterprise Linux</strong> using <strong>GNU Bash</strong> scripting and the useradd command.</p><p>In this lab we will create users manually, automate multiple user creation, assign passwords, add users to a group and delete users.</p><h3>1. Creating a Single User</h3><pre>sudo useradd john</pre><h3>Command Explanation</h3><p>sudo→ Runs the command with administrative privileges.</p><p>useradd→ Creates a new user account.</p><p>john→ Name of the user being created.</p><h3>Verify the User</h3><pre>id john</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*CTJQZnzhlYu0BIBnKGWXjw.png" /></figure><p>This confirms the user was created successfully.</p><h3>2. Creating a Group</h3><p>Before assigning users to a group, the group must exist.</p><pre>sudo groupadd developers</pre><h3>Command Explanation</h3><p>groupadd→ Creates a new group.</p><p>developers→ Name of the group.</p><h3>Verify the Group</h3><pre>cat /etc/group | grep developers</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*BfxuvXUQQfBb3TAMAPkCFA.png" /></figure><p>This confirms the group was created successfully.</p><h3>3. Automating Multiple User Creation with a Bash Script</h3><p>Instead of creating users one by one, we can automate the process using a <strong>Bash script</strong>.</p><h3>Create the Script</h3><pre>vim create_users.sh</pre><h3>Script</h3><pre>#!/bin/bash<br><br>for i in {1..5}<br>do<br>sudo useradd -m user$i<br>echo &quot;user$i:Password123&quot; | sudo chpasswd<br>sudo usermod -aG developers user$i<br>done</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*AeoHNO06oCp3KW1lajXS0w.png" /></figure><h3>Script Explanation</h3><p>#!/bin/bash→ Tells the system to run the script using the Bash shell.</p><p>for i in {1..5}→ Generates numbers from <strong>1 to 5</strong>.</p><p>user$i→ Creates usernames such as <strong>user1, user2, user3, user4, user5</strong>.</p><p>sudo useradd -m user$i→ Creates the user and automatically creates the user’s <strong>home directory</strong>.</p><p>echo &quot;user$i:Password123&quot; | sudo chpasswd→ Sets the password <strong>Password123</strong> for the user.</p><p>sudo usermod -aG developers user$i→ Adds the user to the <strong>developers group</strong>.</p><p>done→ Ends the loop.</p><h3>4. Make the Script Executable</h3><pre>chmod +x create_users.sh</pre><h3>Command Explanation</h3><p>chmod +x→ Gives the script permission to execute.</p><h3>5. Run the Script</h3><pre>./create_users.sh</pre><p>This will automatically create:</p><pre>user1<br>user2<br>user3<br>user4<br>user5</pre><p>Each user will:</p><ul><li>Have a home directory</li><li>Have a password</li><li>Belong to the <strong>developers group</strong></li></ul><h3>6. Verify the Users</h3><p>Check a user:</p><pre>id user1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*uZQHXiQGR00TQT89krpehA.png" /></figure><p>This confirms the user was successfully added to the <strong>developers group</strong>.</p><h3>7. Creating Multiple Users from a File</h3><p>In many environments, administrators receive a list of usernames from HR or another system. Instead of creating each user manually, we can store the usernames in a file and automate the process using a script in <strong>GNU Bash</strong> on <strong>Red Hat Enterprise Linux</strong>.</p><h3>Step 1 — Create the User List File</h3><pre>vim users.txt</pre><p>Example content:</p><pre>Alice<br>Bob<br>Charles<br>David<br>Emma</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/190/1*jduU8LL9K5ac9NtB9SbrQQ.png" /></figure><p>Each line represents one username.</p><h3>Step 2 — Create the Script</h3><pre>vim create_users_from_file.sh</pre><p>Add the script:</p><pre>#!/bin/bash<br><br>for user in $(cat users.txt)<br>do<br>sudo useradd -m $user<br>echo &quot;$user:Password123&quot; | sudo chpasswd<br>sudo usermod -aG developers $user<br>echo &quot;$user has been added&quot;<br>done</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*L2ilPtNm9N3aBHCdZ0QmtQ.png" /></figure><h3>Script Explanation</h3><p>for user in $(cat users.txt)→ Reads each username from the <strong>users.txt</strong> file.</p><p>useradd -m $user→ Creates the user and the user’s home directory.</p><p>echo &quot;$user:Password123&quot; | chpasswd→ Sets a default password for the user.</p><p>usermod -aG developers $user→ Adds the user to the <strong>developers group</strong>.</p><p>echo &quot;$user has been added&quot;→ After user have been created return that each users have been added</p><p>done→ Ends the loop.</p><h3>Make the Script Executable</h3><pre>chmod +x create_users_from_file.sh</pre><h3>Run the Script</h3><pre>./create_users_from_file.sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*iyUSS-ZomDiujlL0Td1pOQ.png" /></figure><h3>Verify the Users</h3><p>Check a user:</p><pre>id alice</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*qo74Q0wtZjLyF59iJ2_FNQ.png" /></figure><p>This confirms the users were created and added to the <strong>developers group</strong>.</p><h3>8. Deleting Multiple Users with a Bash Script</h3><p>Sometimes administrators need to remove multiple users from the system. Instead of deleting each user manually, a Bash script can automate the process in <strong>GNU Bash</strong> on <strong>Red Hat Enterprise Linux</strong>.</p><h3>Create the Script</h3><pre>vim delete_users.sh</pre><h3>Script</h3><pre>#!/bin/bash<br><br>for i in {1..5}<br>do<br>sudo userdel -r user$i<br>echo &quot;user$i has been deleted&quot;<br>done</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*8NW4695f2Dh1x0ZggcnNMw.png" /></figure><h3>Script Explanation</h3><p>#!/bin/bash→ Specifies that the script should run using the Bash shell.</p><p>for i in {1..5}→ Generates numbers from <strong>1 to 5</strong>.</p><p>sudo userdel -r user$i→ Deletes users <strong>user1 to user5</strong> and removes their home directories.</p><p>r→ Removes the user’s home directory along with the account.</p><p>echo &quot;user$i has been deleted&quot;→ After each users have been deleted it returns that each users have been deleted</p><p>done→ Ends the loop.</p><h3>Make the Script Executable</h3><pre>chmod +x delete_users.sh</pre><h3>Run the Script</h3><pre>./delete_users.sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*QOmvvrmtQjRn59gUGBGRyg.png" /></figure><h3>Verify the Users Are Deleted</h3><pre>id user1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*m3-HwW5JPcDmyZGcWJEjUA.png" /></figure><p>This confirms the user account has been removed from the system.</p><p><strong>Day 16 Completed</strong></p><p>Bash scripting was used to automate linux user management by creating multiple users, assigning passwords, adding them to a group, creating users from a file and also deleting users to simulate real system administration tasks.</p><p>Skills practiced:</p><ul><li>Linux user management</li><li>Group management</li><li>Bash scripting automation</li><li>Creating multiple users automatically</li><li>Assigning passwords</li><li>Adding users to groups</li><li>Deleting users with a script</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53c72307e047" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bash Scripting (Loops & Conditionals)]]></title>
            <link>https://medium.com/@bamidelebabatundem/bash-scripting-loops-conditionals-abd718878b95?source=rss-99476dec8c94------2</link>
            <guid isPermaLink="false">https://medium.com/p/abd718878b95</guid>
            <category><![CDATA[bash-script]]></category>
            <category><![CDATA[rhel]]></category>
            <category><![CDATA[variables]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[bash]]></category>
            <dc:creator><![CDATA[Babatunde]]></dc:creator>
            <pubDate>Tue, 10 Mar 2026 16:44:05 GMT</pubDate>
            <atom:updated>2026-10-03T09:22:08.806Z</atom:updated>
            <content:encoded><![CDATA[<h3>Objective</h3><p>Learn how to automate tasks using <strong>GNU Bash</strong> on <strong>Red Hat Enterprise Linux</strong> by understanding:</p><ul><li>Bash scripts</li><li>Variables</li><li>Conditional statements</li><li>Loops (for and while)</li><li>Testing scripts</li></ul><h3>1. Bash Script</h3><h3>Explanation</h3><p>A <strong>Bash script</strong> is a file containing commands that are executed automatically by the Bash shell.</p><p>It helps system administrators automate repetitive tasks.</p><h3>Example Script</h3><p>Create the script:</p><pre>vim hello.sh</pre><p>Add:</p><pre>#!/bin/bash<br>	echo &quot;Hello, Welcome to Bash scripting&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*mhwcszHyU5Hy1potogzlBw.png" /></figure><h3>Command Explanation</h3><ul><li>vim hello.sh → creates and edits a new script file</li><li>#!/bin/bash → tells the system to run the script using Bash</li><li>echo → prints text to the terminal</li></ul><p><strong>Make script executable and run:</strong></p><pre>chmod+x hello.sh<br>./hello.sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*76lQ9Rr9HYyKeDizeVuK6w.png" /></figure><ul><li>chmod +x → gives the script execution permission</li><li>./hello.sh → runs the script</li></ul><h3>2. Variables</h3><h3>Explanation</h3><p>A <strong>variable</strong> stores data that can be reused in a script.</p><p>This makes scripts easier to modify and reuse.</p><h3>Example Script</h3><p>Create the script:</p><pre>vim variable.sh</pre><p>Add:</p><pre>#!/bin/bash<br><br>name=&quot;Admin&quot;<br><br>echo &quot;Welcome $name&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*4GjE_xtVuBGnJZPkiDaPKg.png" /></figure><h3>Command Explanation</h3><ul><li>name=&quot;Admin&quot; → creates a variable called <strong>name</strong></li><li>$name → retrieves the value stored in the variable</li><li>echo → prints the message containing the variable value</li></ul><p><strong>Run the script:</strong></p><pre>chmod+x variable.sh<br>./variable.sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*7ZvHmA7hY5Vx2AOJJE_PIA.png" /></figure><h3>3. Conditional Statements (if)</h3><h3>Explanation</h3><p>A <strong>conditional statement</strong> allows a script to make decisions based on a condition.</p><p>The <strong>if statement</strong> checks whether a condition is true before running commands.</p><h3>Example Script</h3><p>Create the script:</p><pre>vim condition.sh</pre><p>Add:</p><pre>#!/bin/bash<br>num=10<br>if [$num -gt 5 ]<br>then<br>echo &quot;Number is greater than 5&quot;<br>fi</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*XKTQ9ZJjlH45l1Y2u7ATjA.png" /></figure><h3>Command Explanation</h3><ul><li>num=10 → assigns the value <strong>10</strong> to the variable <strong>num</strong></li><li>if → begins the conditional statement</li><li>[ ] → used to test conditions</li><li>gt → means <strong>greater than</strong></li><li>then → commands to execute if condition is true</li><li>fi → ends the if statement</li></ul><p><strong>Run the script:</strong></p><pre>chmod +x condition.sh<br>./condition.sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*By1xGOoFICWzFu0KOzrEEw.png" /></figure><h3>4. For Loop</h3><h3>Explanation</h3><p>A <strong>for loop</strong> repeats a command for multiple values.</p><p>It is useful when performing the same action several times.</p><h3>Example Script</h3><p>Create the script:</p><pre>vim forloop.sh</pre><p>Add:</p><pre>#!/bin/bash<br><br>for i in 1 2 3 4 5<br>do<br>echo &quot;Number: $i&quot;<br>done</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*uj35ZM7s2YDG0w7WG2rczQ.png" /></figure><h3>Command Explanation</h3><ul><li>for i in 1 2 3 4 5 → loop through the numbers 1 to 5</li><li>i → variable that stores each number during the loop</li><li>do → begins the loop commands</li><li>done → ends the loop</li><li>echo → prints each value</li></ul><p>Note: If you have more that one nu</p><p><strong>Run the script:</strong></p><pre>chmod +x forloop.sh<br>./forloop.sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*8muJ5_ozIy09JrxiPFQuuQ.png" /></figure><p>This confirms the loop executed five times.</p><p>In a <strong>production environment</strong>, a <strong>for loop</strong> in <strong>GNU Bash</strong> is mostly used to <strong>repeat the same task on multiple items automatically</strong>. This saves time and avoids doing the same command many times manually.</p><p>Here are common real-world uses:</p><h3>1️. Managing Multiple Files</h3><p>Run the same command on many files.</p><p>Example: change permission for many files.</p><pre>#!/bin/bash<br><br>for file in *.log<br>do<br>chmod 640 $file<br>done</pre><p>Explanation:</p><p>The loop goes through every .log file and changes its permission.</p><h3>2️. Managing Multiple Servers</h3><p>Admins often run commands on several servers.</p><p>Example:</p><pre>#!/bin/bash<br><br>for server in server1 server2 server3<br>do<br>ssh $server &quot;uptime&quot;<br>done</pre><p>Explanation:</p><p>The loop connects to each server and checks system uptime.</p><h3>3️. Creating Multiple Users</h3><p>Useful for automation in <strong>Red Hat Enterprise Linux</strong>.</p><pre>#!/bin/bash<br><br>for user in user1 user2 user3<br>do<br>sudo useradd $user<br>done</pre><p>Explanation:</p><p>Creates multiple users automatically.</p><h3>4️. Running System Checks</h3><p>Admins may check disk or service status repeatedly.</p><p>Example:</p><pre>#!/bin/bash<br><br>for service in sshd httpd firewalld<br>do<br>systemctl status $service<br>done</pre><p>Explanation:</p><p>Checks the status of multiple services.</p><p><strong>Note:</strong></p><blockquote><em>In a production environment, a for loop is commonly used to automate repetitive tasks such as managing multiple files, users, servers, or services.</em></blockquote><h3>5. While Loop</h3><h3>Explanation</h3><p>A <strong>while loop</strong> executes commands repeatedly while a condition remains true.</p><h3>Example Script</h3><p>Create the script:</p><pre>vim whileloop.sh</pre><p>Add:</p><pre>#!/bin/bash<br><br>count=1<br>while [ $count -le 5 ]<br>do<br>echo &quot;Count: $count&quot;<br>((count++))<br>done</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*4xgZUAYp8rjWAd2BuXhwYw.png" /></figure><h3>Command Explanation</h3><ul><li>count=1 → initializes the variable</li><li>while → begins the loop</li><li>[ $count -le 5 ] → condition (less than or equal to 5)</li><li>((count++)) → increases the value of <strong>count</strong> by 1</li><li>done → ends the loop</li></ul><p><strong>Run the script:</strong></p><pre>chmod +x whileloop.sh<br>./whileloop.sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*MGeBC_zfmmIoR7WLKyPEdg.png" /></figure><h3>Practical Lab: Check if a User Exists</h3><h3>Explanation</h3><p>This script checks if a user exists in the system using the id command.</p><h3>Script</h3><p>Create the script:</p><pre>vim check_user.sh</pre><p>Add:</p><pre>#!/bin/bash<br><br>read -p &quot;Enter username: &quot; user<br>if id &quot;$user&quot; &amp;&gt;/dev/null<br>then<br>echo &quot;User exists&quot;<br>else<br>echo &quot;User does not exist&quot;<br>fi</pre><h3>Command Explanation</h3><ul><li>read -p → prompts the user for input</li><li>id username → checks if the user exists in the system</li><li>&amp;&gt;/dev/null → hides the command output</li><li>if → checks the command result</li><li>echo → displays the result message</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*Z_CoyF0ux2Wh5IO9ixj2vQ.png" /></figure><p><strong>Run the script:</strong></p><pre>chmod +x check_user.sh<br>./check_user.sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*sEywMZDDyCTDncoYLTgsiA.png" /></figure><ul><li>We run the <strong>./check_user.sh</strong> script and check for root user and it returned user exists</li><li>And we checked for another user that is not on the system which is <strong>david </strong>but it returned user does not exist because we don’t have david as part of our users.</li><li>This is mostly used in a production environment to check for users</li></ul><p><strong>Day 15 Completed</strong></p><p>Bash scripts was created and executed to automate basic tasks. Variables, conditional statements, and loops were used to control script behavior, and each script was tested to confirm the expected output.</p><p><strong>Skills practiced:</strong></p><ul><li>Bash scripting fundamentals</li><li>Variables</li><li>Conditional logic</li><li>For loops</li><li>While loops</li><li>Script testing and validation</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=abd718878b95" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SELinux Basics]]></title>
            <link>https://medium.com/@bamidelebabatundem/selinux-basics-6c3820f7a6a2?source=rss-99476dec8c94------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c3820f7a6a2</guid>
            <category><![CDATA[rhel]]></category>
            <category><![CDATA[selinux]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[logs]]></category>
            <dc:creator><![CDATA[Babatunde]]></dc:creator>
            <pubDate>Sat, 07 Mar 2026 13:15:53 GMT</pubDate>
            <atom:updated>2026-09-30T11:38:05.584Z</atom:updated>
            <content:encoded><![CDATA[<h3>Objective</h3><p>On one <strong>Red Hat Enterprise Linux</strong> machine, learn how to check, manage, and troubleshoot SELinux security policies, understand security contexts, and practice real-world troubleshooting using the <strong>Apache HTTP Server</strong> web service.</p><h3>What is SELinux?</h3><p>SELinux (Security-Enhanced Linux) is a security system that controls how processes access files, ports, and system resources.</p><p>It uses <strong>Mandatory Access Control (MAC)</strong> — meaning even the root user can be restricted by policy rules.</p><h3>1. Check SELinux Status</h3><pre>getenforce</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*aI8x0Ompt20srmPiDOHRQg.png" /></figure><p>Detailed view:</p><pre>sestatus</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*oKJ8J9M9fGEzGPSCEUBurg.png" /></figure><p>Shows:</p><ul><li>SELinux status</li><li>Current mode</li><li>Policy type</li></ul><h3>SELinux Modes (Brief)</h3><ul><li><strong>Enforcing</strong> → SELinux <strong>actively blocks</strong> unauthorized actions (Best for production).</li><li><strong>Permissive</strong> → SELinux <strong>only logs</strong> violations but does not block actions (Used for troubleshooting).</li><li><strong>Disabled</strong> → SELinux is <strong>completely turned off</strong> (Not recommended).</li></ul><h3>2. Change SELinux Mode (Temporary)</h3><pre>sudo setenforce 0      #Permissive<br>sudo setenforce 1      #Enforcing</pre><p>Temporary — resets after reboot.</p><h3>3. Change SELinux Mode Permanently (Using Vim)</h3><pre>sudo vim /etc/selinux/config</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZIz6QAZpXG1JUU1SG0i3uw.png" /></figure><p><em>Note:</em></p><p>You cannot add multiple modes at the same time.</p><p>Only one mode is allowed because the system needs <strong>one security state</strong> after reboot.</p><ul><li>SELINUX=enforcing</li><li>SELINUX=permissive</li><li>SELINUX=disabled</li></ul><p>Then reboot:</p><pre>sudo reboot</pre><h3>4. Understanding SELinux Contexts</h3><p>To view contexts:</p><pre>ls -Z</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HKzQOp_T0LO2UQe8yzuEOg.png" /></figure><h3>SELinux Context Structure</h3><pre>user : role : type : level</pre><p>Meaning:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/1*gUW62bGb8S4uikMSt2RctA.png" /></figure><h3>Common Context Types</h3><ul><li><strong>httpd_sys_content_t</strong> → Web server files</li><li><strong>var_log_t</strong> → Log files</li><li><strong>ssh_home_t</strong> → SSH files</li><li><strong>unlabeled_t</strong> → Missing label</li></ul><p>If you see <strong>undefined or unlabeled</strong>, SELinux may block access.</p><h3>Practical Lab: Trigger SELinux Denial</h3><p><strong>Objective:</strong> Trigger a SELinux denial by placing a web file in an unauthorized directory, then identify and fix the issue so <strong>Apache HTTP Server</strong> can access the file under <strong>Security-Enhanced Linux</strong> policy.</p><h3>Step 1 — Install Apache if not installed yet</h3><pre>sudo dnf install httpd-y<br>sudo systemctl start httpd<br>sudo systemctl enable httpd</pre><h3>Step 2 — Create Web File in Wrong Location</h3><pre>sudo mkdir /myweb<br>sudo vim /myweb/index.html</pre><p>Add:</p><pre>SELinux Practical Test Page</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*O950isBpSZdTrkbKQhppmw.gif" /></figure><h3>Step 3 — Link to Web Directory</h3><pre>sudo ln -s /myweb/index.html /var/www/html/index.html</pre><h3>Step 4 — Test in Browser</h3><pre>http://localhost</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y_XCL_ua9DPW-em4BpAWRw.png" /></figure><h3>Step 5 — Check SELinux Logs</h3><pre>sudo ausearch -m avc -ts recent</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-L8VnEM9DWp19ww98KEwUg.png" /></figure><p>If output shows:</p><pre>no matches</pre><p>Then no SELinux violation was logged.</p><h3>Step 6 — Fix Context</h3><pre>sudo restorecon -Rv /var/www/html</pre><p>This restores correct SELinux labels.</p><h3>Step 7 — Return to Enforcing Mode</h3><pre>sudo setenforce 1</pre><h3>Advanced Admin Command (Professional Level)</h3><h4>Manage SELinux Ports</h4><p>Used when running services on non-standard ports.</p><p>Example (Allow HTTP on port 8080):</p><pre>sudo semanage port -a -t http_port_t -p tcp 8080</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*qHucImFpH6T77rb5YQ-r0A.png" /></figure><p>(Install tool if missing):</p><pre>sudo dnf install policycoreutils-python-utils-y</pre><p>You can confirm that the port was added correctly using <strong>semanage port -l</strong> and filtering for HTTP ports.</p><pre>sudo semanage port -l | grep http_port_t</pre><h3>Important SELinux Commands Summary</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*y747NG1swJ7N6NYaPJ5nwQ.png" /></figure><p><strong>Day 14 Completed</strong></p><p>Learned how SELinux enforces security policies, how to manage SELinux modes, understand security contexts, troubleshoot access denials, and perform real-world web server testing using Apache.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c3820f7a6a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>