<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: MUHAMMAD ARBAB ANJUM</title>
    <description>The latest articles on DEV Community by MUHAMMAD ARBAB ANJUM (@arbab529).</description>
    <link>https://dev.to/arbab529</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F873431%2Fdb0fa07b-400a-4129-a2ab-878612d59e2b.png</url>
      <title>DEV Community: MUHAMMAD ARBAB ANJUM</title>
      <link>https://dev.to/arbab529</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arbab529"/>
    <language>en</language>
    <item>
      <title>Expose localhost to the network using Cloudflare Tunnel</title>
      <dc:creator>MUHAMMAD ARBAB ANJUM</dc:creator>
      <pubDate>Mon, 25 Aug 2025 23:41:55 +0000</pubDate>
      <link>https://dev.to/arbab529/expose-localhost-to-the-network-using-cloudflare-tunnel-33ge</link>
      <guid>https://dev.to/arbab529/expose-localhost-to-the-network-using-cloudflare-tunnel-33ge</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Install cloudflared&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Download from: https://github.com/cloudflare/cloudflared/releases
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Change Dir&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd C:\cloudflared\
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Login to Cloudflare&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cloudflared tunnel login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Create tunnel&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cloudflared tunnel create nextjs-tunnel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Route DNS&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cloudflared tunnel route dns nextjs-tunnel test.myworkly.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Create config.yml file in C:\cloudflared\config.yml&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tunnel: nextjs-tunnel
credentials-file: C:\Users\%USERNAME%\.cloudflared\[your-tunnel-id].json

ingress:
  - hostname: test.domain.com
    service: http://localhost:3000
  - service: http_status:404
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Quick Test&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cloudflared tunnel --hostname test.domain.com --url http://localhost:3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Run tunnel pointing directly to Next.js&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cloudflared tunnel --config config.yml run nextjs-tunnel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>cloudflarechallenge</category>
      <category>reverseproxy</category>
      <category>linux</category>
      <category>devops</category>
    </item>
    <item>
      <title>How to setup nginx proxy?</title>
      <dc:creator>MUHAMMAD ARBAB ANJUM</dc:creator>
      <pubDate>Mon, 11 Aug 2025 11:07:02 +0000</pubDate>
      <link>https://dev.to/arbab529/how-to-setup-nginx-proxy-1keg</link>
      <guid>https://dev.to/arbab529/how-to-setup-nginx-proxy-1keg</guid>
      <description>&lt;p&gt;Update nginx.conf file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen 443 ssl;
        server_name test.domain.com;

        ssl_certificate D:/nginx/ssl/cert.crt;
        ssl_certificate_key D:/nginx/ssl/priv.key;

        # Enable SSL protocols and settings
        ssl_protocols TLSv1.2 TLSv1.3;
        ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;

        # Security headers
        add_header X-Content-Type-Options nosniff;
        # add_header X-Frame-Options DENY;  # (Commented out, uncomment if needed)
        add_header X-XSS-Protection "1; mode=block";

        location / {
            proxy_pass http://localhost:5000;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;

            # WebSocket support
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update Host:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;127.0.0.1 -&amp;gt; test.domain.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>nginx</category>
      <category>devops</category>
      <category>ssl</category>
    </item>
    <item>
      <title>Setup Firewall on Linux</title>
      <dc:creator>MUHAMMAD ARBAB ANJUM</dc:creator>
      <pubDate>Sat, 26 Jul 2025 06:40:30 +0000</pubDate>
      <link>https://dev.to/arbab529/setup-firewall-on-linux-371o</link>
      <guid>https://dev.to/arbab529/setup-firewall-on-linux-371o</guid>
      <description>&lt;p&gt;Let's secure the server with firewall:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install ufw
sudo ufw status
sudo ufw enable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will enable the firewall and allow all incoming and outgoing traffic. To allow incoming traffic on a specific port&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Allow Inbound:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ufw allow 22
sudo ufw allow 22,80,443 #allow multiple ports
sudo ufw allow 8000:9000/tcp #allow port range
sudo ufw allow from 192.168.1.100 #allow specific IP
sudo ufw allow from 192.168.1.100 to any port 22 #restrict to a port
sudo ufw allow HTTP #allow HTTP
sudo ufw allow https #allow HTTPS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Deny Inbound&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ufw deny 21 #deny port
sudo ufw deny out to 10.0.0.5 #deny to an IP
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Allow Outbound&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ufw default allow outgoing #allow all
sudo ufw allow out 443 #on specific port
sudo ufw allow out to 1.1.1.1 #allow specific IP
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Check Rules&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ufw status numbered
sudo ufw delete 3 #Delete rule number 3
sudo ufw reset #reset all rules
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Example: NodeJs App running with Local DB&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ufw allow 22/tcp
sudo ufw allow from your_ip to any port 22 #limit SSH to your IP
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 3000/tcp
sudo ufw deny 5432/tcp  #PostgreSQL (Port 5432): Explicitly block external access
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;PostgreSQL should already bind to 127.0.0.1 (check /etc/postgresql/.../postgresql.conf):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;listen_addresses = 'localhost'  #Ensures DB is not exposed externally
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Other ports allow (If necessary):&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Allow HTTP/HTTPS&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ufw allow out 80/tcp
sudo ufw allow out 443/tcp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Allow SMTP (If sending emails)&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ufw allow out 25/tcp
sudo ufw allow out 587/tcp  # For TLS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Allow NTP (For time sync)&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ufw allow out 123/udp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Block All Other Outbound&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you want strict outbound control, first allow what’s needed, then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ufw default deny outgoing
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Enable UFW &amp;amp; Verify Rules&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ufw enable
sudo ufw status verbose
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Protection against brute-force
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install fail2ban
sudo systemctl enable fail2ban
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Configuration for fail2ban&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo nano /etc/fail2ban/jail.local
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[DEFAULT]
# Ban IPs for 1 hour (3600 seconds)
bantime = 3600
# Maximum retries before ban
maxretry = 5
# Time window for maxretry
findtime = 600
# Ban IPs on all ports (not just the attacked service)
banaction = ufw
# Whitelist your own IP (replace `your_ip`)
ignoreip = 127.0.0.1/8 ::1 your_ip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>vps</category>
      <category>nginx</category>
      <category>linux</category>
      <category>firewall</category>
    </item>
    <item>
      <title>How to do Node.js Deployment on VPS</title>
      <dc:creator>MUHAMMAD ARBAB ANJUM</dc:creator>
      <pubDate>Sat, 26 Jul 2025 06:25:49 +0000</pubDate>
      <link>https://dev.to/arbab529/how-to-do-nodejs-deployment-on-vps-259o</link>
      <guid>https://dev.to/arbab529/how-to-do-nodejs-deployment-on-vps-259o</guid>
      <description>&lt;h2&gt;
  
  
  1- Server Setup
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Log in to your server&lt;br&gt;
Once your machine is up and running SSH to the server.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh root@IP.x.x.x
OR
ssh -i key.pem root@IP.x.x.x
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;System Update/Upgrade&lt;br&gt;
Now we are inside the machine, update and upgrade the system.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt update -y
sudo apt upgrade -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Change Password&lt;br&gt;
Once system has been updated/upgraded You can change your password (optional)&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;passwd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Add a new non-root user and add it to sudoers&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo usermod -aG sudo username
sudo -l -U username #Verify the user has sudo access

OR 

useradd -m -s /bin/bash username
groups username
usermod -aG sudo username 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Set password for new user&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo passwd username
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now log in as a new user:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh username@192.IP.IP.IP
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Authenticate using SSH and Restrict Password Login (Recommended)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-keygen -t ed25519 -C "user@domain.com"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To view all public keys&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Windows: C:\Users\YourUser\.ssh\id_ed25519.pub
Linux: cat ~/.ssh/id_ed25519.pub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copy the content of the public(.pub) key file. Paste the public key into the file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nano ~/.ssh/authorized_keys
ssh-add -k ~/.ssh/id_ed25519 #add it to the ssh utility
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Disable password login if you only want authentication using ssh only.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo nano /etc/ssh/sshd_config
Search for: PasswordAuthentication=no
For root user: PermitRootLogin=no
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now restart the ssh service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo service ssh restart "OR" sudo systemctl restart ssh
ssh username@IP.x.x.x #Login With ssh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2- Secure server with firewall
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dev.to/arbab529/setup-firewall-on-linux-371o"&gt;View firewall setup doc&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3- Setup Nginx on Ubuntu
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Install and configure nginx on your ubuntu server&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install nginx
sudo systemctl start nginx #start service
sudo systemctl enable nginx #enable service
sudo vim /etc/nginx/sites-available/default #Create new server block config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do nginx configuration for your site:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server {
  listen 80;  # Listen on port 80, the default HTTP port
  server_name localhost;  # The server name, here it is set to localhost

  root /var/www/html;  # The root directory where files are served from
  index index.html index.htm;  # The default files to serve

  location / {
    try_files $uri $uri/ =404;  # Try to serve the requested URI, if not found return a 404
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;If /var/html/www doesn't exist&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo mkdir -p /var/www/html
sudo chown -R $USER:$USER /var/www/html #Change ownership of the document root directory to the current user
sudo chmod -R 755 /var/www/html #set permission
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Test the nginx server serving file:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /var/www/html
touch index.html #write some dummy code
sudo nginx -t #test the configuration
sudo systemctl reload nginx #reload to apply changes
Visit URL/IP to see if it works
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Setup Ratelimit&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo vim /etc/nginx/nginx.conf

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the following code to the http block&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http {
  limit_req_zone $binary_remote_addr zone=mylimit:10m rate=2r/s;

  ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;$binary_remote_addr: This is a variable that holds the client’s IP address in a binary format. Using the binary format saves memory, which is important when dealing with large numbers of requests&lt;/li&gt;
&lt;li&gt;zone=mylimit:10m: This specifies the name and size of the shared memory zone used to store the state of rate limits. mylimit means the name of the zone. 10m means that the size of the zone is 10 megabytes.&lt;/li&gt;
&lt;li&gt;rate=2r/s: means that each IP address is allowed to make 2 requests per second&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Edit nginx server block config to apply rate limit&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo vim /etc/nginx/sites-available/default

# Add following inside server block
server {
  ...

  location / {
    limit_req zone=mylimit burst=20 nodelay;
    try_files $uri $uri/ =404;
  }

  ...
}

sudo nginx -t
sudo systemctl reload nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4- Setup SSL Certificate
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install certbot python3-certbot-nginx
sudo vim /etc/nginx/sites-available/default


server {
  ...
  server_name test.arbab.com;
  ...
}

sudo nginx -t

# Obtain an SSL
sudo certbot --nginx -d test.arbab.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Follow the prompts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enter the email address associated with your domain registrar account.&lt;/li&gt;
&lt;li&gt;Accept the terms of service.&lt;/li&gt;
&lt;li&gt;Press Enter to continue.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Renew Certificate&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo certbot renew --dry-run #To check if the certificate is close to expiring
sudo certbot renew
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>node</category>
      <category>vps</category>
      <category>nginx</category>
      <category>linux</category>
    </item>
    <item>
      <title>How to push your code on new github/gitlab account?</title>
      <dc:creator>MUHAMMAD ARBAB ANJUM</dc:creator>
      <pubDate>Thu, 17 Jul 2025 01:19:34 +0000</pubDate>
      <link>https://dev.to/arbab529/how-to-add-push-your-code-on-new-githubgitlab-account-2723</link>
      <guid>https://dev.to/arbab529/how-to-add-push-your-code-on-new-githubgitlab-account-2723</guid>
      <description>&lt;p&gt;1- Create SSH Key:&lt;br&gt;
&lt;code&gt;ssh-keygen -t ed25519 -C "arbab@gmail.com"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;2- Command to Start SSH Agent&lt;br&gt;
&lt;code&gt;eval "$(ssh-agent -s)"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;3- Command to add your key&lt;br&gt;
&lt;code&gt;ssh-add ~/.ssh/id_ed25519&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;4- Copy your ssh key from ~/.ssh/id_ed25519.pub &lt;/p&gt;

&lt;p&gt;5- Paste Keys:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For Github: Paste in project_repo &amp;gt; settings &amp;gt; Deploy Keys&lt;/li&gt;
&lt;li&gt;For Gitlab: Paste in project_repo &amp;gt; settings &amp;gt; Repository &amp;gt; Deploy Keys &lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>git</category>
      <category>gitlab</category>
      <category>devops</category>
      <category>programming</category>
    </item>
    <item>
      <title>Linux From Zero to Hero</title>
      <dc:creator>MUHAMMAD ARBAB ANJUM</dc:creator>
      <pubDate>Mon, 19 May 2025 18:11:17 +0000</pubDate>
      <link>https://dev.to/arbab529/linux-from-zero-to-hero-131g</link>
      <guid>https://dev.to/arbab529/linux-from-zero-to-hero-131g</guid>
      <description>&lt;h2&gt;
  
  
  Access Linux Server Remotely Using SSH
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh -i ./keyPair.pem ubuntu@remote_host

If you want to access the server on your VM, then in VirtualBox, you have to change the network setting from `NAT` to `Bridge Adapter`

# Sometimes you need to install this package to access your server remotely. 

sudo apt install openssh-server
systemctl start ssh

# Check ssh service
systemctl status ssh.service

# Access from Windows:
ssh ubuntu@remote_host
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  SCP (Secure Copy Protocol)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# from current server to remote
scp /local/file ubuntu@remote_host:/path/

# from remote to current server
scp -v ubuntu@remote_host:/path/ &amp;lt;current_server_path&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Editors
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;vim Editor&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vim abc.txt

Press i -&amp;gt; start editing the file
Esc + d -&amp;gt; to stop editing
esc, shift + :wq -&amp;gt; Save File
:q! -&amp;gt; quit without Save
shift + g -&amp;gt; Move to end of file
small g two times --&amp;gt; Move to top of file
/hello -&amp;gt; will seach the hello word in the file
Press n -&amp;gt; To move to the next search location of that word
?search → use ? when searching from bottom to top
Shift + * → to search on the highlighted word
:%s/searc_word/replace_word/g → Replace word, %s (Substitue), /g (Globally) 
U → undo everything
Ctrl + r → redo everything
Press O → to enter text in the next line where you are currently
Press Shift + O → to enter text in before the line where you are currently
Shift + I → insert in the start of the line
Shift + A → insert in the end of the line
Press r → to replace the selected character
Press d d  → press d two times to delete the line
:e! → revert all the changes
Type 15 and press dd two times to delet 15 lines from the place where your cursor is currently
Press p → to paste the line in the clipboard
Shift + p → paste before the line where you are currently
Shift +v → select the lines you want to copy → press y → to copy the selected lines
:set nu → show line number next to each line in the editor
:set nonu → hide line number next to each line in the editor
:syntax on → show colors in the file → mostly for code purpose
:syntax off → hide colors
:100 → jump to line number 100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  User Account Management
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;View all users&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;less /etc/passwd

# View with encrypted password
less /etc/shadow
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Create user&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Add user
useradd &amp;lt;username&amp;gt;

# Check if user created or not?
id &amp;lt;username&amp;gt;

# Personalize user info while account creation?
useradd -g &amp;lt;group_name&amp;gt; -s /bin/bash -c &amp;lt;comment here&amp;gt; -m -d /home/&amp;lt;user_name&amp;gt; &amp;lt;user_name&amp;gt;

# -g -&amp;gt; Group
# -s -&amp;gt; default shell
# -c -&amp;gt; comment or any message 
# -m -&amp;gt; Want to make home dir or not
# -d -&amp;gt; if -m then -d means directory path

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Delete user&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;userdel &amp;lt;user_name&amp;gt;
userdel -r &amp;lt;user_name&amp;gt; (remove home dir also)
userdel -f &amp;lt;user_name&amp;gt; (force delete even if user is logged in)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Modify user&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Add user to new group but default group will remain same
usermod -G &amp;lt;group_name&amp;gt; &amp;lt;user_name&amp;gt;

# Change default group
usermod -g &amp;lt;group_name&amp;gt; &amp;lt;user_name&amp;gt;

# -L/-U -&amp;gt; Lock or unlock user from login
# -p -&amp;gt; change password OR passed &amp;lt;user_name&amp;gt;
# -s -&amp;gt; Change shell type
# -m -d -&amp;gt; move home content to the new folder

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Group Management
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Create Group&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# New group
groupadd &amp;lt;group_name&amp;gt;

# View all groups
less /etc/group 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Password Aging
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;For single user:&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#One time using 'chage' command
#Making default for every new user by making change in /etc/login.def file

#Format:

chage [-m mindays] [-M maxdays] [-d lastday] [-I inactive] [-E expiredate] [-W warndays] &amp;lt;user_name&amp;gt;

-m -&amp;gt; No of days required a user is allowed to change password
-M -&amp;gt; Max no of days password is valid
-d -&amp;gt; Days since Jan 1, 1970 that password was last changed
-I -&amp;gt; No of days after password expire, account is disable
-E -&amp;gt; Days since Jan 1, 1970 that password was last changed


# Password Aging matrix

less /etc/shadow
username:password:last_pass_change:min_pass_age:max_pass_age:warning_period:inactivity_period:expiration_date:unused

# Example: password valid until 90 days and when 10 days are left throw a warning.
chage -M 90 -W 10 &amp;lt;user_name&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;For multiple user:&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nano /etc/login.def

PASS_MAX_DAYS 90
PASS_MIN_DAYS 10
PASS_MIN_LEN 8
PASS_WARN_AGE 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  SU and SUDO Command
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#switch to the home directory of the login user
su - &amp;lt;user_name&amp;gt; 

#Even after switching user stays in same dir of previous user
su &amp;lt;user_name&amp;gt; 

#switch to root user
su -

# view details of sudoers
less /etc/sudoers

#Update sudoers file from anywhere 
visudo 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Firewall
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Tools for managing firewall.

- iptables
- firewalld -&amp;gt; latest now a days
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Linux Hardening
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Making linux system more secure by turning off things you don't need, limiting access, and add extra layer of protection to keep it safe from hackers. List below to have secure system:&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- Principle of Least Privilege (PoLP)
- Minimize Attack Surface
- Keep the System Updated
- Strong Authentication and Password Policies
- Secure Remote Access
- Logging and Monitoring 

**Enable Logging:** Use tools like rsyslog, syslog-ng, or
journald to record system events.

**Log Analysis:** Use intrusion detection tools like
fail2ban or AIDE to monitor logs and detect suspicious activity.

Regularly check system logs and automate alerts for
unusual activities (e.g., /var/log/auth.log).

- Firewall Configuration
- File System Security
- System Auditing
- Disable Unused Network Services and Ports
- File and Directory Permissions
- Kernel Hardening
- Use Security Tools and Enhanced Security Applications
- Data Backup and Recovery
- Physical Security
- Secure Boot Process
- Network Security Configurations
- Intrusion Detection and Prevention
- Authentication Management
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Cockpit - Tool
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Access your server with help of Web UI&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install cockpit
access using: http://&amp;lt;server_IP&amp;gt;:9090
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  LogRotate - Tool
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Log files location in linux
cd /var/log/

# Config Files

/etc/logrotate.conf
/etc/logrotate.d

Log Files Location

/var/log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>devops</category>
      <category>linux</category>
      <category>aws</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Shell Scripting - Zero to Hero</title>
      <dc:creator>MUHAMMAD ARBAB ANJUM</dc:creator>
      <pubDate>Sun, 04 May 2025 08:32:34 +0000</pubDate>
      <link>https://dev.to/arbab529/shell-scripting-zero-to-hero-5he3</link>
      <guid>https://dev.to/arbab529/shell-scripting-zero-to-hero-5he3</guid>
      <description>&lt;p&gt;Shell scripting consists of set of commands to perform a task.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Different types of shells:&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;bash &lt;/li&gt;
&lt;li&gt;sh&lt;/li&gt;
&lt;li&gt;ksh&lt;/li&gt;
&lt;li&gt;tsh&lt;/li&gt;
&lt;li&gt;fish&lt;/li&gt;
&lt;li&gt;zsh (Extended version of bash with more advanced features)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;What is my shell type?&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo $0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;How to check supported shells?&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat /etc/shells
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;What is shebang?&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It specifies which interpreter should be used to execute the script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Basic shell script&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
echo "hello world!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;How to execute script?&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Make sure script have execute permission rwx.
1- ./file.sh
2- path/file.sh
3- bash file.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;How to add comments?&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1- single line comment 

#comment

2- Multiline comment

&amp;lt;&amp;lt;comment 

---- Your Comment Here ----

comment

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Variables:
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;How to use variables?&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
person="Arbab Anjum"
hostName=$(hostname)
readonly role="superadmin"

echo $person is using $hostName and role is $role

------
&amp;gt; Output: Arbab Anjum is using ubuntu and role is superadmin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Array:
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;How to define and get value of an array?&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Set Value:

myArray = (1 2 3 Hello "World");

Get Value:

echo "${myArray[0]}"
echo "${myArray[1]}"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;How to find length of an array?&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo "${#myArray[*]}"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;How to get specific values?&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo "${myArray[*]:1}"
echo "${myArray[*]:1:2}" // from index 1, get 2 values
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;How to update an array?&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myArray+=(New 7 8)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;How to store the key value pairs?&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;declare -A myKeyValArray
myKeyValArray=([name]="Arbab Anjum",[city]="London")
echo "Name is ${myKeyValArray[name]}"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  String Operations:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myVar="My name is Muhammad Arbab Anjum"
echo "Length: ${#myVar}"
echo "Uppercase: ${myVar^^}"
echo "Length: ${myVar,,}"
echo "Replace (name) with (Name): ${myVar/name/Name}"
echo "Slice: ${myVar:6:13}" 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  User Interaction:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo "What is your name? "
read name
echo "Name is $name"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;read in same line:&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;read -p "What is your name: " name
echo "My name is $name"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Arithmetic Operations
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x=10
y=2
let mul=$x*$y # use 'let' to tell it's a mathematical operation
echo "Multiplication: $mul"
echo "Addition: $(($x+$y))"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conditional Statement
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;If Else&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;Example: 1&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if [[ $marks -gt 40 ]]
then
    echo "Pass!"
else
    echo "Fail!"
fi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Example: 2&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if [[ $marks -gt 40 ]]
then
    echo "Above 40!"
elif [[ $marks -eq 30 ]]
    echo "Fail!"
then
    echo "Equal 30!"
else
    echo "Less than 30!"
fi

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Example: 3 || Logical operation&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if [[ $age -gt 18 ]] &amp;amp;&amp;amp; [[ $country -eq "London" ]]
then
    echo "Pass!"
else
    echo "Fail!"
fi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Equal &amp;gt; -eq/==
Greater than or equal to &amp;gt; -ge
Less than or equal to &amp;gt; -le
Not equal to &amp;gt; -ne/!=
Greater than &amp;gt; -gt
Less than &amp;gt; -lt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Switch Case&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo "Choose an option below:"
echo "a =  To see current data"
echo "b =  list all files in current directory"

read choice

case $choice in
    a) date;;
    b) ls;;
    *) echo "Not a valid input"
esac
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;For Loop&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;Example: 1&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for i in 1 2 3 4 5
do
      echo "Number: $i"
done
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Example: 2&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for i in {1..10}
do
      echo "Number: $i"
done
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Example: 3 - Getting value from file name.txt&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FILE='/home/arbab/name.txt'
for name in $(cat $FILE)
do
      echo "Name is: $name"
done
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Example: 4 - Getting value from file name.txt&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myArray=(1 2 3 4 5 6 7)
for (( i=0; i&amp;lt;${#myArray[*]}; i++ ))
do
      echo "Value is: ${myArray[$i]}"
done
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;while Loop &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;Code keeps executing till the statement is true&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;count=0
num=10

while [ $count -le $num ]
do
    echo "Number: $count"
    let count++
done
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Until loop&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;Code keeps executing till the statement is false&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a=10

until[ $a -eq 1 ]
do
    echo "Number: $a"
    let a--
done
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Read content from CSV file&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while IFS="," read f1 f2 f3
do
    echo "$f1"
    echo "$f2"
    echo "$f3"
done &amp;lt; file_name.csv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Function
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Example 1:&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function myFun{
    echo "--------"
    echo "Welcome"
    echo "--------"
}

# Calling Function
myFunc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Example 2:&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myFun(){
    echo "--------"
    echo "Welcome"
    echo "--------"
}

# Calling Function
myFun
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Example 2: With arguments&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
myFun(){
    local num1=$1 # $1-&amp;gt; First argument: 5
    local num2=$2 # $2-&amp;gt; Second argument: 2
    let result=$num1+$num2 
    echo "--------"
    echo "Sum: $result"
    echo "--------"
}

# Calling Function
myFun 5 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Example 2: Send arguments while executing file&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./file.sh arbab anjum

file.sh:

echo $1 # result: arbab
echo $@ # result: arbab anjum -&amp;gt; $@ means all arguments
echo $# # result: 2 -&amp;gt; number of arguments

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Useful Concept
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;break - To stop the loop&lt;/li&gt;
&lt;li&gt;continue - To stop current iteration of loop and start from the next iteration&lt;/li&gt;
&lt;li&gt;sleep - To create delay between two execution e.g; sleep 1m/1s&lt;/li&gt;
&lt;li&gt;exit - To stop script to a point. e.g; exit 1&lt;/li&gt;
&lt;li&gt;$? - exit status -  gives you status of previous command if that was successful  - status 0 means success&lt;/li&gt;
&lt;li&gt;basename - strip directory info and only give filename&lt;/li&gt;
&lt;li&gt;dirname - strip the filename and gives dir path&lt;/li&gt;
&lt;li&gt;realpath - gives you full path for a file&lt;/li&gt;
&lt;li&gt;RANDOM - generate random number - echo $RANDOM&lt;/li&gt;
&lt;li&gt;UID - User ID of the logged in user - echo $UID - UID of root user is 0&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Debugging:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Add `set -x` in the script to enable debugging
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Scripts:
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Check if file exist or not&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
FILPATH=/home/test/file.csv
if[[ -f $FILEPATH ]]
then
    echo "FILE EXIST"
else
    echo "FILE DON't EXIST"
fi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;If you want to exit script when a command fail&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;set -e # use this
echo "Hello"
cd /root #fail and skip next execution
pwd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Run script in background&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nohup ./script.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Run Script at specific time using At command
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;at 12:09 AM # Run and hit enter it will ask what to do 
bash ./script.sh

atq -&amp;gt; to check scheduled job
atrm &amp;lt;id&amp;gt; -&amp;gt; to remove a scheduled job
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Crontab -  Script automation
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;crontab -l # view existing cronjobs
crontab -e # Create New

Format:

* * * * * cd /home/arbab/ &amp;amp;&amp;amp; ./runfile.sh

Stars from Right To Left
* -&amp;gt; Day of Week (0-6) Sunday=0
* -&amp;gt; month 1-12
* -&amp;gt; Day of month (1-31)
* -&amp;gt; hour 0-23
* -&amp;gt; minute 0-59

https://crontab.guru
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Mini Projects
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Monitoring free RAM Space&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
FREE_SPACE=$(free -mt | grep "Total" | awk '{print $4}')
TH=500

if [[ $FREE_SPACE -lt $TH ]]
then
    echo "Normal Memory!"
else
    echo "Running out of memory!"
fi

#--------- Comments ---------
#free -mt -&amp;gt; show total free memory
#grep "Total" -&amp;gt; pick the line containing word total
#awk '{print $4}' print 4th column value
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Monitoring free disk Space and send an alert email&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
FREE_DISK_SPACE=$(df -H | egrep -v "Filesystem|tmpfs" | grep "sda2" | awk '{print $5}' | tr -d %)
TH=90
TO=user@gmail.com

if [[ $FREE_DISK_SPACE -lt $TH ]]
then
    echo "Disk has enough space!" | mail -s "Disk Space Alert" $TO
else
    echo "Low disk space!"
fi

#--------- Comments ---------
#configure postfix to send emails
#df -h -&amp;gt; show all disk usage
#egrep -v "Filesystem|tmpfs" -&amp;gt; Remove Filsystem and tmps line from output
#grep "sda2" -&amp;gt; search sda2
#awk '{print $5}' print 5th column value
#tr -d % -&amp;gt; truncate/delete % from output
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Move files having size more than 20MB to achieve folder&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;!/bin/bash
# Version: 1
# Date: 19 April 2025

#Variables
BASE=/home/arbab/myFiles
DAYS=10
DEPTH=1
RUN=0

#check if the directory is present or not

if [[ ! -d $BASE ]]
then
    echo "Dir doesn't exist: $BASE"
    exit 1
fi

#create 'archive' folder if not present

if [[ ! -d $BASE/archive ]]
then
    mkdir archive
fi

#Find list of files largest than 20MB

for i in `find $BASE -maxdepth $DEPTH -type f -size +20M`
do
    if [[ $RUN -eq 0 ]]
    then
        echo "[$(date "+%y-%m-%d %H:%M:%S")] archiving $i ==&amp;gt; $BASE/archive"
        gzip $i || exit 1
        mv $i.gz $BASE/archive || exit 1
    fi
done

## ||  runs the command on right side when left side result is false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Automate user account creation&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash

# script should execute with sudo/root access.
if [[ "${UID}" -ne 0 ]]
then
    echo 'Please run with root or sudo user'
    exit 1
fi

# user should provide atleast one argument as username else guide him
if [[ "${#}" -lt 1 ]]
then
    echo 'Usage: ${0} USER_NAME [COMMENT]...'
    exit 1
fi

# ${0} -&amp;gt; Tells the name of script
# store first argument as username

USER_NAME="{$1}"

# All other arguments as comment
shift
COMMENT="{$@}"

# create a password

RANDOM_PASS=$(date +%s%N)
# seconds and nano seconds

# create a user
useradd -c "${COMMENT}" -m $USER_NAME

# -c -&amp;gt; comment
# -m -&amp;gt; Make Dir

# Check if user created successfully or not

if [[ $? -ne 0 ]]
then
    echo "Failed to create user"
    exit 1
fi

# set password for user
echo $PASSWORD | passwd --stdin $USER_NAME

# Check if password is successfully set or not

if [[ $? -ne 0 ]]
then
    echo "Failed to create user"
    exit 1
fi

# force password change on first login
passwd -e $USER_NAME

# Display username password and hostname

echo "Username: $USER_NAME"
echo "Username: $PASSWORD"
echo "Hostname: $(hostname)"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>devops</category>
      <category>linux</category>
      <category>bash</category>
      <category>aws</category>
    </item>
  </channel>
</rss>
