<?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"><channel><title><![CDATA[Lokendra]]></title><description><![CDATA[Lokendra]]></description><link>https://blog.lokendrabhat.com.np</link><generator>RSS for Node</generator><lastBuildDate>Wed, 07 Oct 2026 15:13:38 GMT</lastBuildDate><atom:link href="https://blog.lokendrabhat.com.np/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Restore — What Happens After ddrescue Saves Your Data]]></title><description><![CDATA["ddrescue got your data off the dying drive. Now what? This is where you actually get it back."


🚑 The Big Picture First
A lot of people think ddrescue restores data. It doesn't — not directly.
Here]]></description><link>https://blog.lokendrabhat.com.np/restore-what-happens-after-ddrescue-saves-your-data</link><guid isPermaLink="true">https://blog.lokendrabhat.com.np/restore-what-happens-after-ddrescue-saves-your-data</guid><category><![CDATA[Linux]]></category><category><![CDATA[System administration]]></category><category><![CDATA[Devops]]></category><category><![CDATA[data recovery]]></category><dc:creator><![CDATA[Lokendra Bhat]]></dc:creator><pubDate>Sun, 29 Mar 2026 13:15:00 GMT</pubDate><content:encoded><![CDATA[<img src="https://cdn.hashnode.com/uploads/covers/645bd7f3d3761288bf03ed2c/1e1243e6-3eac-44d6-b2c3-cc9f79aa4bf8.svg" alt="" style="display:block;margin:0 auto" />

<blockquote>
<p><em>"ddrescue got your data off the dying drive. Now what? This is where you actually get it back."</em></p>
</blockquote>
<hr />
<h2>🚑 The Big Picture First</h2>
<p>A lot of people think ddrescue <em>restores</em> data. It doesn't — not directly.</p>
<p>Here's the honest breakdown:</p>
<table>
<thead>
<tr>
<th>Tool</th>
<th>Job</th>
<th>Analogy</th>
</tr>
</thead>
<tbody><tr>
<td><code>ddrescue</code></td>
<td>Copies a dying drive into a safe image</td>
<td>🚑 The ambulance</td>
</tr>
<tr>
<td><code>dd</code> / <code>mount</code> / <code>fsck</code></td>
<td>Works with that image to get files back</td>
<td>🏥 The hospital</td>
</tr>
<tr>
<td><code>TestDisk</code> / <code>PhotoRec</code></td>
<td>Digs deeper when the filesystem is broken</td>
<td>🔬 The surgeon</td>
</tr>
</tbody></table>
<p><strong>ddrescue is step one. Restore is everything after.</strong></p>
<p>The full journey looks like this:</p>
<pre><code class="language-plaintext">Dying Drive
    │
    ▼
ddrescue  ──────────►  rescue.img  
             (your safe copy — don't touch the original again)
                              
              ┌─────────────┼──────────────┐
              ▼               ▼                ▼
         Mount it       Clone it      Fix &amp; carve it
       (browse files)  (new drive)   (broken filesystem)
</code></pre>
<hr />
<h2>🧰 Four Ways to Restore — Pick What Fits</h2>
<hr />
<h3>🗂️ Option 1 — Just Browse &amp; Copy Files</h3>
<p><strong>When to use it:</strong> The drive had one bad sector but the filesystem is mostly fine. You just want to grab your documents, photos, etc.</p>
<pre><code class="language-bash"># Create a mount point
sudo mkdir -p /mnt/recovery

# Mount the image (read-only — always read-only first!)
sudo mount -o loop,ro rescue.img /mnt/recovery

# Browse it like a normal folder
ls /mnt/recovery
cp /mnt/recovery/Documents ~/restored-docs
</code></pre>
<blockquote>
<p>✅ Safest option. The <code>ro</code> (read-only) flag means you <strong>cannot accidentally modify</strong> your rescued image.</p>
</blockquote>
<p>When you're done:</p>
<pre><code class="language-bash">sudo umount /mnt/recovery
</code></pre>
<hr />
<h3>💿 Option 2 — Clone the Image onto a New Drive</h3>
<p><strong>When to use it:</strong> You want a full working replacement of the original drive — same partition layout, same OS, same everything — just on new hardware.</p>
<pre><code class="language-bash">sudo dd if=rescue.img of=/dev/sdb bs=4M status=progress
</code></pre>
<table>
<thead>
<tr>
<th>Part</th>
<th>Meaning</th>
</tr>
</thead>
<tbody><tr>
<td><code>if=rescue.img</code></td>
<td>Input: your rescued image</td>
</tr>
<tr>
<td><code>of=/dev/sdb</code></td>
<td>Output: the new blank drive</td>
</tr>
<tr>
<td><code>bs=4M</code></td>
<td>Read/write in 4MB chunks (much faster than default)</td>
</tr>
<tr>
<td><code>status=progress</code></td>
<td>Shows live progress so you're not staring at a blank terminal</td>
</tr>
</tbody></table>
<blockquote>
<p>⚠️ <strong>Double-check</strong> <code>of=/dev/sdb</code> — this overwrites the destination completely. Get the device name wrong and you'll overwrite the wrong disk. Run <code>lsblk</code> first to confirm.</p>
</blockquote>
<p>After cloning, run a filesystem check on the new drive before using it:</p>
<pre><code class="language-bash">sudo fsck -y /dev/sdb1
</code></pre>
<hr />
<h3>🔧 Option 3 — Fix a Corrupted Filesystem on the Image</h3>
<p><strong>When to use it:</strong> The image mounted but files are missing, the filesystem shows errors, or <code>mount</code> refuses to open it at all.</p>
<p>The image contains a filesystem (ext4, NTFS, FAT32, etc.) that may have been damaged before or during rescue. <code>fsck</code> repairs it.</p>
<p><strong>Step 1 — Set up a loop device so fsck can see the image as a disk:</strong></p>
<pre><code class="language-bash">sudo losetup -f --show rescue.img
# Outputs something like: /dev/loop0
</code></pre>
<p><strong>Step 2 — Run the filesystem check:</strong></p>
<pre><code class="language-bash"># For ext4 (most Linux drives)
sudo fsck.ext4 -y /dev/loop0

# For FAT32 / exFAT (USB drives, SD cards)
sudo fsck.fat -y /dev/loop0

# For NTFS (Windows drives)
sudo ntfsfix /dev/loop0
</code></pre>
<p>The <code>-y</code> flag auto-answers "yes" to all repair prompts.</p>
<p><strong>Step 3 — Mount and check:</strong></p>
<pre><code class="language-bash">sudo mount -o loop /dev/loop0 /mnt/recovery
ls /mnt/recovery
</code></pre>
<p><strong>Step 4 — Detach when done:</strong></p>
<pre><code class="language-bash">sudo umount /mnt/recovery
sudo losetup -d /dev/loop0
</code></pre>
<hr />
<h3>🔬 Option 4 — Deep Recovery with TestDisk &amp; PhotoRec</h3>
<p><strong>When to use it:</strong> The partition table is gone, the filesystem is unreadable, files were deleted, or <code>mount</code> and <code>fsck</code> both fail. This is the surgical option.</p>
<p>These tools work directly on the image file — no mounting required.</p>
<hr />
<h4>🗺️ TestDisk — Recovers Lost Partitions &amp; Boot Sectors</h4>
<p>TestDisk rebuilds the structural layer of a disk — partition tables, boot records, MFT entries. Use it when the drive "disappears" or shows as unallocated space.</p>
<pre><code class="language-bash">sudo testdisk rescue.img
</code></pre>
<p>It launches an interactive text UI. The general flow:</p>
<pre><code class="language-plaintext">1. Select the image file
2. Choose partition table type (usually Intel/MBR or GPT)
3. Analyse → Quick Search
4. If partitions found → Write to fix the table
5. Reboot or re-mount and check
</code></pre>
<blockquote>
<p>💡 TestDisk is non-destructive on first analysis — it won't change anything until you explicitly choose <strong>Write</strong>.</p>
</blockquote>
<hr />
<h4>📷 PhotoRec — Carves Raw Files by Signature</h4>
<p>PhotoRec ignores the filesystem entirely. It scans raw bytes looking for known file signatures — the magic bytes that mark the start of a JPEG, PDF, ZIP, MP4, and 480+ other formats.</p>
<pre><code class="language-bash">sudo photorec rescue.img
</code></pre>
<p>Interactive prompts will ask:</p>
<ul>
<li><p>Which partition to scan (or the whole image)</p>
</li>
<li><p>Where to save recovered files (use a <strong>different drive</strong>)</p>
</li>
<li><p>Which file types to look for (or all of them)</p>
</li>
</ul>
<p><strong>What to expect:</strong> PhotoRec will create folders named <code>recup_dir.1</code>, <code>recup_dir.2</code>, etc., filled with recovered files. Filenames are generic (<code>f1234567.jpg</code>) but the content is intact.</p>
<blockquote>
<p>⚠️ PhotoRec output can be thousands of files. Give it a separate folder on a large drive.</p>
</blockquote>
<hr />
<h2>🗺️ Choosing the Right Tool — Decision Tree</h2>
<pre><code class="language-plaintext">Start here: Do you have rescue.img from ddrescue?
│
├── YES
│    │
│    ├── Can you mount the image normally?
│    │    │
│    │    ├── YES → Option 1: Just mount &amp; copy files
│    │    │
│    │    └── NO
│    │         │
│    │         ├── Want a full working drive clone?
│    │         │    └── YES → Option 2: dd clone to new drive
│    │         │
│    │         ├── Filesystem errors / missing files?
│    │         │    └── YES → Option 3: fsck repair
│    │         │
│    │         └── Partition gone / files deleted / fsck fails?
│    │              └── YES → Option 4: TestDisk + PhotoRec
│    │
└── NO → Go run ddrescue first!
</code></pre>
<hr />
<h2>🔢 The Complete Workflow — Start to Finish</h2>
<p>Here's the full rescue-and-restore process in one place:</p>
<p><strong>Step 1 — Rescue the dying drive:</strong></p>
<pre><code class="language-bash"># Pass 1: fast sweep
sudo ddrescue -d -n /dev/sda rescue.img rescue.log

# Pass 2: targeted retry on bad sectors
sudo ddrescue -d -r3 /dev/sda rescue.img rescue.log
</code></pre>
<p><strong>Step 2 — Try the simple mount first:</strong></p>
<pre><code class="language-bash">sudo mount -o loop,ro rescue.img /mnt/recovery
# If this works, just copy your files and you're done
</code></pre>
<p><strong>Step 3 — If mount fails, repair the filesystem:</strong></p>
<pre><code class="language-bash">sudo losetup -f --show rescue.img   # get /dev/loop0
sudo fsck.ext4 -y /dev/loop0
sudo mount /dev/loop0 /mnt/recovery
</code></pre>
<p><strong>Step 4 — If files are still missing, use PhotoRec:</strong></p>
<pre><code class="language-bash">sudo photorec rescue.img
</code></pre>
<p><strong>Step 5 — If you want a full clone on a new drive:</strong></p>
<pre><code class="language-bash">sudo dd if=rescue.img of=/dev/sdb bs=4M status=progress
sudo fsck -y /dev/sdb1
</code></pre>
<hr />
<h2>🛡️ Golden Rules of Restore</h2>
<p><strong>1. Never modify the original device again.</strong> Once ddrescue has the image, the original drive's job is done. Unplug it. Store it somewhere safe. Every extra read shortens its life.</p>
<p><strong>2. Always try read-only mount first.</strong> Before running any repair tool, try <code>mount -o ro</code>. If your files are there, you're done — no need to risk a repair operation.</p>
<p><strong>3. Work from the image, not a copy of the image.</strong> Repair tools like <code>fsck</code> modify the image in place. Keep a backup copy of <code>rescue.img</code> before running them — just in case a repair makes things worse.</p>
<pre><code class="language-bash">cp rescue.img rescue_backup.img   # keep a clean copy first
sudo fsck.ext4 -y /dev/loop0      # now repair the working copy
</code></pre>
<p><strong>4. Save recovered files to a different drive.</strong> Never save PhotoRec output back to the same image or the same drive you're recovering from.</p>
<p><strong>5. Be patient with PhotoRec.</strong> It can take hours on a large drive. Let it finish. Interrupting it mid-scan loses progress.</p>
<hr />
<h2>📦 Tool Summary</h2>
<table>
<thead>
<tr>
<th>Tool</th>
<th>What it fixes</th>
<th>Install</th>
</tr>
</thead>
<tbody><tr>
<td><code>mount</code></td>
<td>Browse a working filesystem</td>
<td>Built-in</td>
</tr>
<tr>
<td><code>dd</code></td>
<td>Clone image to a new physical drive</td>
<td>Built-in</td>
</tr>
<tr>
<td><code>fsck</code></td>
<td>Repairs corrupted filesystem structures</td>
<td>Built-in</td>
</tr>
<tr>
<td><code>ntfsfix</code></td>
<td>Basic NTFS repair (Windows drives)</td>
<td><code>ntfs-3g</code> package</td>
</tr>
<tr>
<td><strong>TestDisk</strong></td>
<td>Lost partitions, deleted boot sectors</td>
<td><code>testdisk</code> package</td>
</tr>
<tr>
<td><strong>PhotoRec</strong></td>
<td>Carves files when filesystem is gone</td>
<td>Ships with <code>testdisk</code></td>
</tr>
</tbody></table>
<p>Install TestDisk + PhotoRec in one go:</p>
<pre><code class="language-bash"># Ubuntu / Debian
sudo apt install testdisk

# Fedora
sudo dnf install testdisk

# macOS
brew install testdisk
</code></pre>
<hr />
<p>Hence, The restore phase is where you actually <em>get your data back</em> — ddrescue just made it possible. In order of effort:</p>
<ol>
<li><p><strong>Try mounting first</strong> — takes 10 seconds, might be all you need</p>
</li>
<li><p><strong>Run fsck</strong> — fixes most filesystem-level problems</p>
</li>
<li><p><strong>Use TestDisk</strong> — for lost partitions and structural damage</p>
</li>
<li><p><strong>Use PhotoRec</strong> — the last resort that still finds files when everything else fails</p>
</li>
</ol>
<p>Most recoveries end at step 1 or 2. The deeper tools exist for the hard cases — and they're genuinely good at what they do.</p>
<hr />
<p><em>Companion to the ddrescue guide · TestDisk/PhotoRec by Christophe Grenier ·</em> <a href="https://www.cgsecurity.org/wiki/TestDisk"><em>TestDisk Docs</em></a></p>
]]></content:encoded></item><item><title><![CDATA[ddrescue — Your Data's Last Lifeline]]></title><description><![CDATA["Your hard drive is making a clicking sound. Your stomach drops. Don't panic — ddrescue has your back."


🤔 What Even Is ddrescue?
Imagine your hard drive is a library. Some books are fine. Some are ]]></description><link>https://blog.lokendrabhat.com.np/ddrescue-your-data-s-last-lifeline</link><guid isPermaLink="true">https://blog.lokendrabhat.com.np/ddrescue-your-data-s-last-lifeline</guid><category><![CDATA[Devops]]></category><category><![CDATA[Linux]]></category><category><![CDATA[System administration]]></category><category><![CDATA[ddrescue]]></category><category><![CDATA[data recovery]]></category><dc:creator><![CDATA[Lokendra Bhat]]></dc:creator><pubDate>Sat, 28 Mar 2026 15:53:45 GMT</pubDate><content:encoded><![CDATA[<img src="https://cdn.hashnode.com/uploads/covers/645bd7f3d3761288bf03ed2c/0880374f-3171-4337-9a8e-2dfe4a57d96f.svg" alt="" style="display:block;margin:0 auto" />

<blockquote>
<p><em>"Your hard drive is making a clicking sound. Your stomach drops. Don't panic — ddrescue has your back."</em></p>
</blockquote>
<hr />
<h2>🤔 What Even Is ddrescue?</h2>
<p>Imagine your hard drive is a library. Some books are fine. Some are wet and falling apart. A normal copy tool (<code>dd</code>) would try to photocopy every single page in order — and the moment it hits a ruined page, it <strong>stops</strong>.</p>
<p><strong>ddrescue is smarter.</strong> It says:</p>
<blockquote>
<p><em>"Skip the damaged pages for now. Let me grab everything I can first — then I'll come back and carefully try the tough ones."</em></p>
</blockquote>
<p>That's it. That's the whole idea. It's a <strong>data rescue tool</strong> that copies data from broken, dying, or corrupted storage devices — hard drives, CDs, DVDs, USB sticks — while being smart enough to work <em>around</em> the damage.</p>
<hr />
<h2>🔧 Installing ddrescue</h2>
<p>Before anything else, let's get it on your machine. One important note:</p>
<blockquote>
<p>⚠️ <strong>Don't confuse</strong> <code>gddrescue</code> <strong>(GNU ddrescue) with</strong> <code>dd_rescue</code> <strong>(different tool, different developer).</strong> You want the GNU one.</p>
</blockquote>
<pre><code class="language-bash"># Ubuntu / Debian
sudo apt install gddrescue

# Fedora
sudo dnf install ddrescue

# Arch Linux
sudo pacman -S ddrescue

# macOS (via Homebrew)
brew install ddrescue
</code></pre>
<p>Check it's working:</p>
<pre><code class="language-bash">ddrescue --version
# Should print: GNU ddrescue 1.27 (or similar)
</code></pre>
<hr />
<h2>🗺️ The Basic Shape of a Command</h2>
<pre><code class="language-bash">ddrescue [options]  source  destination  [logfile]
</code></pre>
<p>Three things you need to know:</p>
<table>
<thead>
<tr>
<th>Part</th>
<th>What it is</th>
<th>Example</th>
</tr>
</thead>
<tbody><tr>
<td><code>source</code></td>
<td>The broken thing you're reading FROM</td>
<td><code>/dev/sda</code></td>
</tr>
<tr>
<td><code>destination</code></td>
<td>Where the rescued data goes TO</td>
<td><code>rescue.img</code></td>
</tr>
<tr>
<td><code>logfile</code></td>
<td>A progress notebook (optional but <strong>please use it</strong>)</td>
<td><code>rescue.log</code></td>
</tr>
</tbody></table>
<h3>🗒️ Why the logfile matters so much</h3>
<p>The logfile is ddrescue's <strong>memory</strong>. Without it:</p>
<ul>
<li><p>❌ If your computer crashes mid-rescue, you start from zero</p>
</li>
<li><p>❌ You can't retry only the bad sectors later</p>
</li>
<li><p>❌ You lose all progress tracking</p>
</li>
</ul>
<p>With it:</p>
<ul>
<li><p>✅ Stop and resume anytime</p>
</li>
<li><p>✅ Run multiple targeted passes</p>
</li>
<li><p>✅ Know exactly what was saved and what wasn't</p>
</li>
</ul>
<p><strong>Always use a logfile. No exceptions.</strong></p>
<hr />
<h2>⚙️ Options — Plain English Edition</h2>
<p>These are the switches you can flip. Let's cut through the jargon.</p>
<hr />
<h3><code>-n</code>  ·  <code>--no-scrape</code> — <em>"Just grab the easy stuff first"</em></h3>
<pre><code class="language-bash">ddrescue -n /dev/sda rescue.img rescue.log
</code></pre>
<p>Normally ddrescue tries damaged areas repeatedly during its first pass. This flag says <strong>skip them</strong> — just read the healthy parts as fast as possible.</p>
<p><strong>Use it when:</strong> The drive is barely alive and you need data off it <em>fast</em> before it dies completely.</p>
<hr />
<h3><code>-r N</code>  ·  <code>--retry-passes=N</code> — <em>"How many times to bang on a stuck door"</em></h3>
<pre><code class="language-bash">ddrescue -r 3 /dev/sda rescue.img rescue.log
</code></pre>
<p>After the main read, ddrescue retries failed sectors. This sets how many times.</p>
<table>
<thead>
<tr>
<th>Value</th>
<th>Meaning</th>
</tr>
</thead>
<tbody><tr>
<td><code>-r 0</code></td>
<td>Don't retry at all</td>
</tr>
<tr>
<td><code>-r 3</code></td>
<td>Try each bad sector 3 times</td>
</tr>
<tr>
<td><code>-r -1</code></td>
<td>Keep retrying forever (default)</td>
</tr>
</tbody></table>
<p><strong>Use it when:</strong> You want to control how long the retry phase runs. <code>-r 3</code> is a good balanced choice.</p>
<hr />
<h3><code>-d</code>  ·  <code>--direct</code> — <em>"Talk directly to the hardware, skip the middleman"</em></h3>
<pre><code class="language-bash">ddrescue -d /dev/sda rescue.img rescue.log
</code></pre>
<p>Your OS keeps a cache in RAM to speed up reads. For a healthy drive, great. For a broken one, it can interfere with error detection. This flag <strong>bypasses the cache</strong> and reads straight from the device.</p>
<p><strong>Use it when:</strong> Almost always, especially on failing physical drives.</p>
<hr />
<h3><code>-f</code>  ·  <code>--force</code> — <em>"Yes I know the file exists, do it anyway"</em></h3>
<pre><code class="language-bash">ddrescue -f /dev/sda rescue.img rescue.log
</code></pre>
<p>If <code>rescue.img</code> already exists, ddrescue normally refuses to overwrite it (to protect you). This flag overrides that protection.</p>
<blockquote>
<p>🔴 <strong>Be careful.</strong> If you point this at the wrong file, you'll overwrite data you worked hard to rescue. Double-check your paths.</p>
</blockquote>
<hr />
<h3><code>-i POS</code>  ·  <code>--input-position=POS</code> — <em>"Start reading from here, not the beginning"</em></h3>
<pre><code class="language-bash">ddrescue -i 512MiB /dev/sda rescue.img rescue.log
</code></pre>
<p>Tells ddrescue to start reading at a specific byte offset in the source. Useful when only part of a drive is damaged.</p>
<p>You can use human-friendly sizes: <code>512B</code>, <code>10KiB</code>, <code>500MiB</code>, <code>2GiB</code>.</p>
<hr />
<h3><code>-o POS</code>  ·  <code>--output-position=POS</code> — <em>"Start writing from here in the destination"</em></h3>
<pre><code class="language-bash">ddrescue -i 500MiB -o 0 /dev/sda rescue.img rescue.log
</code></pre>
<p>Pairs with <code>-i</code> to let you map a specific part of the source to a specific position in the output.</p>
<hr />
<h3><code>-s SIZE</code>  ·  <code>--size=SIZE</code> — <em>"Only copy this much data"</em></h3>
<pre><code class="language-bash">ddrescue -s 50GiB /dev/sda rescue.img rescue.log
</code></pre>
<p>Limits how much data is copied total. Handy for partial recoveries of large disks — you don't need to image a 4TB drive if the important stuff is in the first 100GB.</p>
<hr />
<h3><code>-b SIZE</code>  ·  <code>--sector-size=SIZE</code> — <em>"Tell ddrescue the disk's page size"</em></h3>
<pre><code class="language-bash">ddrescue -b 4096 /dev/sda rescue.img rescue.log
</code></pre>
<p>Most old drives use 512-byte sectors. Newer drives and SSDs use 4096 bytes (called "4K" or "Advanced Format"). If you're getting weird errors, try this.</p>
<p>For CDs and DVDs, the sector size is <code>2048</code>.</p>
<hr />
<h3><code>-c NUM</code>  ·  <code>--cluster-size=NUM</code> — <em>"How big a chunk to read at once"</em></h3>
<pre><code class="language-bash">ddrescue -c 64 /dev/sda rescue.img rescue.log
</code></pre>
<p>Bigger chunks = faster on healthy areas. Smaller chunks = more precise around damaged areas. ddrescue picks a sensible default; only change this if you know what you're doing.</p>
<hr />
<h3><code>-v</code>  ·  <code>--verbose</code> — <em>"Tell me more of what's happening"</em></h3>
<pre><code class="language-bash">ddrescue -v /dev/sda rescue.img rescue.log
ddrescue -vv /dev/sda rescue.img rescue.log  # even more detail
</code></pre>
<p>Prints more information as it runs. Double <code>-vv</code> goes deeper. Good for diagnosing mysterious failures.</p>
<hr />
<h3><code>-T INTERVAL</code>  ·  <code>--timeout=INTERVAL</code> — <em>"Give up after this long with no progress"</em></h3>
<pre><code class="language-bash">ddrescue -T 30m /dev/sda rescue.img rescue.log
</code></pre>
<p>If ddrescue goes this long without reading any new data, it stops automatically. Useful in scripts or when you can't babysit the process.</p>
<hr />
<h2>🎬 The Three Phases — A Story in Three Acts</h2>
<p>ddrescue doesn't just blindly copy. It works through three distinct acts, each with a different job. Think of it as a heist movie — a plan, the tricky part, and the last-ditch effort.</p>
<hr />
<h3>🟢 Act I — The Quick Sweep</h3>
<p><em>"Don't overthink it. Grab what you can."</em></p>
<p>The moment you run ddrescue, it sprints across the entire drive reading data in <strong>large, hungry chunks</strong>. If a sector gives trouble? It doesn't stop. Doesn't argue. Just marks it in the logfile and moves on.</p>
<p>This is intentional. A dying drive has limited reads left in it. Spending precious time wrestling with one bad sector — while hundreds of good ones sit unread — is a terrible trade. So ddrescue sweeps fast, fills the image with everything easy, and leaves the hard stuff for later.</p>
<p><strong>What you get after Act I:</strong> 90–98% of your data, gathered quickly.</p>
<pre><code class="language-plaintext">[Drive]  ████████████░░█████░████████░░░█████████  →  [Image]
          good  good  bad  good  bad good  good
                             ↑ skipped, noted in log
</code></pre>
<hr />
<h3>🔵 Act II — The Fine-Tooth Comb</h3>
<p><em>"Okay, let's go back and really look at those problem spots."</em></p>
<p>Now ddrescue circles back to every sector it skipped. But this time, instead of reading big blocks, it <strong>shrinks the read size down</strong> — slicing each error zone into tiny pieces and testing them one by one.</p>
<p>Why? Because not all damage is total. A 64KB chunk might have failed because of 512 bad bytes in the middle — and the other 63.5KB is perfectly fine. By zooming in, ddrescue can often <strong>rescue the good parts of a partially damaged block</strong>.</p>
<p>This phase is slower. It's harder on the drive. But it finds data that a simpler tool would have written off entirely.</p>
<p><strong>What you get after Act II:</strong> Many of those "bad" blocks turn out to be only <em>partially</em> bad — and you recover more than you expected.</p>
<pre><code class="language-plaintext">[Bad block from Act I]

Before:  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░  (entire block = unknown)
After:   ████████░░░░████████████░░░████  (most of it = rescued!)
                 ↑              ↑
           truly bad       truly bad
</code></pre>
<hr />
<h3>🟡 Act III — The Last Roll of the Dice</h3>
<p><em>"Some doors just need you to knock more than once."</em></p>
<p>After Acts I and II, a small set of sectors still haven't yielded any data. These are the stubborn ones. In Act III, ddrescue goes back to them and <strong>tries again</strong> — controlled by the <code>-r</code> flag.</p>
<p>This exists because storage errors are sometimes <strong>intermittent</strong>, not permanent. A sector that fails 9 out of 10 times might succeed on try number 10 due to slight temperature changes, drive head realignment, or just luck. ddrescue exploits this by retrying methodically.</p>
<p>You control how hard it tries with <code>-r N</code>. Using <code>-r 3</code> means three extra attempts per sector. Using <code>-r -1</code> means it never gives up.</p>
<p><strong>What you get after Act III:</strong> Every sector that <em>could</em> be recovered, has been.</p>
<pre><code class="language-plaintext">Sector #48291:   ❌ failed  →  ❌ failed  →  ✅ recovered!  (on retry 2)
Sector #91042:   ❌ failed  →  ❌ failed  →  ❌ truly gone
</code></pre>
<blockquote>
<p>💡 <strong>The lesson:</strong> Some data that looks lost in Act I is quietly waiting to be found in Acts II and III. Don't skip the phases.</p>
</blockquote>
<hr />
<h2>🛠️ Real Examples You Can Actually Use</h2>
<h3>The Everyday Rescue</h3>
<p>You've got a failing drive. You want an image of it. This is your starting point:</p>
<pre><code class="language-bash">sudo ddrescue -d /dev/sda rescue.img rescue.log
</code></pre>
<hr />
<h3>The Two-Pass Strategy <em>(recommended for serious cases)</em></h3>
<p>When a drive is really struggling, don't fight it all at once. Do it in two stages:</p>
<pre><code class="language-bash"># Pass 1 — fast, skips bad areas entirely
sudo ddrescue -d -n /dev/sda rescue.img rescue.log

# Pass 2 — goes back and tries bad areas up to 3 times
sudo ddrescue -d -r 3 /dev/sda rescue.img rescue.log
</code></pre>
<blockquote>
<p>💡 Same logfile, same image file. ddrescue picks up exactly where Pass 1 left off.</p>
</blockquote>
<hr />
<h3>Resume After Interruption</h3>
<p>Your computer crashed or you had to stop. Just run the same command again:</p>
<pre><code class="language-bash">sudo ddrescue -d /dev/sda rescue.img rescue.log
# ddrescue reads the logfile and continues from where it stopped
</code></pre>
<p>No extra flags needed. The logfile handles everything.</p>
<hr />
<h3>CD or DVD Recovery</h3>
<p>Optical media has 2048-byte sectors, not 512. Always specify this:</p>
<pre><code class="language-bash">sudo ddrescue -d -b 2048 /dev/cdrom disc.iso disc.log
</code></pre>
<hr />
<h3>Only Rescue a Specific Partition</h3>
<p>If only one partition is damaged, target it directly:</p>
<pre><code class="language-bash">sudo ddrescue /dev/sda2 partition2.img partition2.log
</code></pre>
<hr />
<h3>Reverse Direction</h3>
<p>Some drives have physical head issues. Reading backwards can help:</p>
<pre><code class="language-bash">sudo ddrescue -R /dev/sda rescue.img rescue.log
</code></pre>
<hr />
<h2>✅ Best Practices — The "Don't Shoot Yourself in the Foot" List</h2>
<p><strong>1. Never work on the original device.</strong> Always make an image first. Every read wears out a dying drive. Do your file recovery on the image, not <code>/dev/sda</code>.</p>
<p><strong>2. Mount images read-only.</strong></p>
<pre><code class="language-bash">sudo mount -o loop,ro rescue.img /mnt/recovery
</code></pre>
<p>The <code>ro</code> flag prevents accidental writes to your rescued image.</p>
<p><strong>3. Verify your paths before using</strong> <code>-f</code><strong>.</strong> The force flag can overwrite a recovery image you spent hours building. Look twice.</p>
<p><strong>4. Put the image on a <em>different</em> drive.</strong> Writing the rescue image back to the same failing drive is asking for trouble.</p>
<p><strong>5. Check the logfile to see what was saved.</strong></p>
<pre><code class="language-bash">cat rescue.log
# Shows status of every region: copied, non-tried, bad-sector
</code></pre>
<p><strong>6. Use</strong> <code>ddrescuelog</code> <strong>for more analysis.</strong></p>
<pre><code class="language-bash">ddrescuelog -t rescue.log                   # print totals summary
ddrescuelog -l bad-sectors rescue.log       # list bad sector positions
</code></pre>
<p><strong>7. Pair with file-recovery tools afterward.</strong> ddrescue saves the blocks. These tools find the files inside:</p>
<ul>
<li><p><strong>TestDisk</strong> — recovers lost partitions and boot sectors</p>
</li>
<li><p><strong>PhotoRec</strong> — carves individual files from raw images</p>
</li>
<li><p><strong>Foremost</strong> — file carving by file signature</p>
</li>
</ul>
<hr />
<h2>🧠 Quick Reference - Cheatsheet</h2>
<pre><code class="language-plaintext">ddrescue [options] source destination [logfile]

Most useful flags:
  -n          Skip scraping (fast first pass)
  -r N        Retry bad sectors N times
  -d          Direct hardware access (bypass cache)
  -f          Force overwrite of existing destination
  -i POS      Start reading at offset POS
  -o POS      Start writing at offset POS
  -s SIZE     Copy only SIZE bytes total
  -b SIZE     Set sector size (default 512, CD/DVD: 2048)
  -R          Read in reverse direction
  -v / -vv    Verbose / very verbose output
  -T INTERVAL Stop if no progress for INTERVAL

Recommended two-pass recovery:
  sudo ddrescue -d -n  /dev/sda image.img image.log   # pass 1
  sudo ddrescue -d -r3 /dev/sda image.img image.log   # pass 2
</code></pre>
<hr />
<h2>📦 Works On</h2>
<table>
<thead>
<tr>
<th>Media Type</th>
<th>Example Source</th>
</tr>
</thead>
<tbody><tr>
<td>Hard drive (HDD)</td>
<td><code>/dev/sda</code>, <code>/dev/sdb</code></td>
</tr>
<tr>
<td>SSD</td>
<td><code>/dev/nvme0n1</code></td>
</tr>
<tr>
<td>USB drive</td>
<td><code>/dev/sdc</code></td>
</tr>
<tr>
<td>SD card</td>
<td><code>/dev/mmcblk0</code></td>
</tr>
<tr>
<td>CD / DVD</td>
<td><code>/dev/cdrom</code>, <code>/dev/sr0</code></td>
</tr>
<tr>
<td>Partition</td>
<td><code>/dev/sda1</code>, <code>/dev/sda2</code></td>
</tr>
<tr>
<td>Existing image file</td>
<td><code>old_rescue.img</code></td>
</tr>
</tbody></table>
<hr />
<h2>🔚 Finally</h2>
<p>ddrescue won't save every byte on every drive. Sometimes sectors are simply gone. But it gives <strong>every recoverable sector its best possible chance</strong> — methodically, patiently, and without making things worse.</p>
<p>If your storage device is in trouble:</p>
<ol>
<li><p><strong>Stop using it immediately</strong> — more writes = more damage</p>
</li>
<li><p><strong>Install ddrescue</strong></p>
</li>
<li><p><strong>Run a two-pass rescue to an image file on a healthy drive</strong></p>
</li>
<li><p><strong>Work from the image</strong></p>
</li>
</ol>
<p>The data you save might be irreplaceable. Give it every chance.</p>
<hr />
<p><em>GNU ddrescue · Version 1.27 ·</em> <a href="https://www.gnu.org/software/ddrescue/manual/ddrescue_manual.html"><em>Official Manual</em></a></p>
]]></content:encoded></item><item><title><![CDATA[Mastering SELinux: The Complete Guide for DevOps Engineers]]></title><description><![CDATA[Most teams treat SELinux as an obstacle. The teams that thrive in production treat it as a superpower. Here's everything you need to know to move from frustrated to fluent.


If you've ever Googled a ]]></description><link>https://blog.lokendrabhat.com.np/mastering-selinux-the-complete-guide-for-devops-engineers</link><guid isPermaLink="true">https://blog.lokendrabhat.com.np/mastering-selinux-the-complete-guide-for-devops-engineers</guid><category><![CDATA[Devops]]></category><category><![CDATA[infrastructure]]></category><category><![CDATA[ #SystemAdministration ]]></category><category><![CDATA[SELinux]]></category><category><![CDATA[Linux]]></category><category><![CDATA[Cloud Engineering ]]></category><category><![CDATA[SRE]]></category><category><![CDATA[linux-security]]></category><dc:creator><![CDATA[Lokendra Bhat]]></dc:creator><pubDate>Fri, 27 Mar 2026 04:24:09 GMT</pubDate><content:encoded><![CDATA[<blockquote>
<p><em>Most teams treat SELinux as an obstacle. The teams that thrive in production treat it as a superpower. Here's everything you need to know to move from frustrated to fluent.</em></p>
</blockquote>
<hr />
<p>If you've ever Googled a Linux error only to find the top Stack Overflow answer saying "just run <code>setenforce 0</code>" — you're not alone. It's one of the most common cop-outs in the Linux world. But disabling SELinux in production is like removing the smoke detector because the beeping annoys you.</p>
<p>This guide will give you a thorough understanding of what SELinux actually is, how it works under the hood, how to configure it correctly, and — most importantly — how to debug it without turning it off.</p>
<hr />
<h2>What Is SELinux?</h2>
<p>SELinux (Security-Enhanced Linux) is a <strong>mandatory access control (MAC)</strong> security architecture integrated into the Linux kernel. It was originally developed by the NSA and has been part of the mainline Linux kernel since version 2.6.</p>
<p>Unlike traditional Unix file permissions (DAC — Discretionary Access Control), where the owner of a resource decides who can access it, MAC enforces security policy decisions at the kernel level regardless of what any user or process wants.</p>
<blockquote>
<p>💡 <strong>Key Insight</strong> DAC (traditional permissions) asks: <em>"Does this user have permission?"</em> MAC (SELinux) asks: <em>"Does this process have a policy that allows this action?"</em> Even root is constrained by SELinux policies.</p>
</blockquote>
<hr />
<h3>The Architecture: How SELinux Separates Policy from Enforcement</h3>
<p>SELinux's core design principle is the separation of security policy decisions from their enforcement. Here's how the layers interact:</p>
<img src="https://cdn.hashnode.com/uploads/covers/645bd7f3d3761288bf03ed2c/5ff836d5-6ae4-4f35-b997-6712e1bffba1.png" alt="" style="display:block;margin:0 auto" />

<p>The <strong>Access Vector Cache (AVC)</strong> is the performance trick that makes SELinux viable in production — it caches allow/deny decisions so the policy engine isn't consulted on every single system call.</p>
<hr />
<h3>Security Contexts (Labels) — The Heart of SELinux</h3>
<p>Every file, process, port, and socket in an SELinux system carries a <strong>security context</strong> (also called a label). The format is:</p>
<pre><code class="language-plaintext">user:role:type:level

# Example on a file:
system_u:object_r:httpd_sys_content_t:s0

# Example on a process:
system_u:system_r:httpd_t:s0
</code></pre>
<p>The most important field is the <strong>type</strong> (the third field). SELinux's targeted policy is almost entirely about <strong>type enforcement</strong> — specifying which process types can access which object types.</p>
<hr />
<h3>SELinux Policies: Targeted vs. Strict vs. MLS</h3>
<table>
<thead>
<tr>
<th>Policy</th>
<th>Coverage</th>
<th>Use Case</th>
</tr>
</thead>
<tbody><tr>
<td><code>targeted</code></td>
<td>Specific daemons &amp; services</td>
<td>Default on RHEL/CentOS/Fedora — production standard</td>
</tr>
<tr>
<td><code>minimum</code></td>
<td>Very limited — only critical processes</td>
<td>Low-resource environments</td>
</tr>
<tr>
<td><code>strict</code></td>
<td>All processes confined</td>
<td>High-security environments (rarely used)</td>
</tr>
<tr>
<td><code>mls</code></td>
<td>Multi-Level Security with sensitivity labels</td>
<td>Government / military / classified systems</td>
</tr>
</tbody></table>
<p>For most DevOps engineers, <strong>targeted policy</strong> is what you'll work with. It confines high-risk services (nginx, httpd, sshd, database engines) while leaving most user processes unconfined.</p>
<hr />
<h2>SELinux Modes: Know Your Three States</h2>
<img src="https://cdn.hashnode.com/uploads/covers/645bd7f3d3761288bf03ed2c/d7d90258-c2aa-4f78-a1dc-780662946cf2.png" alt="" style="display:block;margin:0 auto" />

<hr />
<h2>Configuring SELinux: The Right Way</h2>
<h3>Checking Current Status</h3>
<pre><code class="language-bash"># Verbose status including policy, mode, and context info
sestatus

# Quick one-word output: Enforcing / Permissive / Disabled
getenforce
</code></pre>
<h3>Changing Mode Temporarily (No Reboot Needed)</h3>
<pre><code class="language-bash">setenforce 0   # Switch to Permissive — useful for live debugging
setenforce 1   # Switch back to Enforcing
</code></pre>
<blockquote>
<p>💡 <code>setenforce</code> only works when SELinux is not <em>disabled</em>. You cannot use it to go from Disabled</p>
<p>→ Permissive. That requires a config change and reboot.</p>
</blockquote>
<h3>Changing Mode Permanently</h3>
<p>Edit the main config file at <code>/etc/selinux/config</code>:</p>
<pre><code class="language-bash"># /etc/selinux/config

# SELINUX= can take one of these three values:
#   enforcing  - SELinux security policy is enforced.
#   permissive - SELinux prints warnings instead of enforcing.
#   disabled   - No SELinux policy is loaded.

SELINUX=enforcing

# SELINUXTYPE= can take one of these three values:
#   targeted - Targeted processes are protected.
#   minimum  - Modification of targeted policy.
#   mls      - Multi Level Security protection.

SELINUXTYPE=targeted
</code></pre>
<h3>The Filesystem Relabeling Problem</h3>
<p>When you switch from <strong>Disabled → Permissive or Enforcing</strong>, there's a critical step many engineers miss: <strong>filesystem relabeling</strong>. When SELinux was disabled, new files were created without security labels. SELinux needs to relabel all these files on the next boot.</p>
<p>If you skip this step, you'll end up with mislabeled files that cause mysterious denials even for legitimate processes.</p>
<pre><code class="language-bash"># Method 1: Use fixfiles to schedule relabeling on next reboot
# The -F flag forces relabeling even if labels already exist
fixfiles -F onboot

# This creates /.autorelabel — SELinux relabels the FS and reboots automatically
ls -la /.autorelabel

# Method 2: Touch the file manually (equivalent)
touch /.autorelabel

# Method 3: Safe transition — boot with enforcing=0 kernel parameter
# Add temporarily to your bootloader:
# GRUB_CMDLINE_LINUX="enforcing=0"
</code></pre>
<blockquote>
<p>✅ <strong>Best Practice</strong> When re-enabling SELinux after it was disabled, always:</p>
<ol>
<li><p>Set to <strong>permissive</strong> first</p>
</li>
<li><p>Schedule a relabel with <code>fixfiles -F onboot</code></p>
</li>
<li><p>Reboot</p>
</li>
<li><p>Check logs for AVC denials</p>
</li>
<li><p>Only then switch to <strong>enforcing</strong></p>
</li>
</ol>
</blockquote>
<hr />
<h2>Managing File Contexts</h2>
<p>The most common SELinux issue DevOps engineers encounter is an <strong>incorrect file context (label)</strong>. When you move or copy files, they may inherit the wrong context from the destination directory.</p>
<h3>Viewing File Contexts</h3>
<pre><code class="language-bash"># The -Z flag adds the SELinux context column
ls -lZ /var/www/html/

# Example output:
# -rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.html

# View context on a running process
ps -eZ | grep httpd
</code></pre>
<h3>Changing File Context with chcon</h3>
<pre><code class="language-bash"># Change the type label of a single file
chcon -t httpd_sys_content_t /var/www/html/myapp/index.php

# Recursively relabel a directory
chcon -R -t httpd_sys_content_t /var/www/html/myapp/
</code></pre>
<blockquote>
<p>⚠️ <strong>Important:</strong> <code>chcon</code> changes are <strong>temporary</strong> — they will be overwritten during a filesystem relabel. Use <code>semanage fcontext</code> + <code>restorecon</code> for permanent, policy-backed context changes.</p>
</blockquote>
<h3>Permanent Context Changes with semanage</h3>
<pre><code class="language-bash"># Add a permanent file context mapping
semanage fcontext -a -t httpd_sys_content_t "/opt/myapp(/.*)?"

# Apply the policy (restores contexts based on policy)
restorecon -Rv /opt/myapp/

# Verify
ls -lZ /opt/myapp/

# View all custom context mappings you've added
semanage fcontext -l | grep myapp

# View the default file context database
less /etc/selinux/targeted/contexts/files/file_contexts
</code></pre>
<hr />
<h2>SELinux Booleans: Runtime Policy Tuning</h2>
<p>Booleans are <strong>runtime switches</strong> that toggle specific behaviors in the SELinux policy without rewriting or recompiling rules. They're how policy authors say: <em>"this behaviour is safe in some environments but not all — let the admin decide."</em></p>
<pre><code class="language-bash"># List all booleans and their current state
getsebool -a

# Filter to find relevant booleans
getsebool -a | grep httpd

# Verbose listing with descriptions
semanage boolean -l | grep httpd

# Example output:
# httpd_can_network_connect   (off , off)  Allow httpd to make network connections
# httpd_can_sendmail          (off , off)  Allow httpd to send mail

# Turn a boolean on temporarily (lost on reboot)
setsebool httpd_can_network_connect on

# Turn on PERMANENTLY (-P writes to policy — persists across reboots)
setsebool -P httpd_can_network_connect on

# Verify
getsebool httpd_can_network_connect
</code></pre>
<h3>Common Booleans for Web/App Servers</h3>
<table>
<thead>
<tr>
<th>Boolean</th>
<th>What It Enables</th>
</tr>
</thead>
<tbody><tr>
<td><code>httpd_can_network_connect</code></td>
<td>Apache/Nginx to make outbound TCP connections (needed for proxying)</td>
</tr>
<tr>
<td><code>httpd_can_network_connect_db</code></td>
<td>Apache to connect to remote databases</td>
</tr>
<tr>
<td><code>httpd_can_sendmail</code></td>
<td>Apache to send email via sendmail/postfix</td>
</tr>
<tr>
<td><code>httpd_use_nfs</code></td>
<td>Apache to serve content from NFS mounts</td>
</tr>
<tr>
<td><code>httpd_execmem</code></td>
<td>Apache to use executable memory (needed by some PHP/Python apps)</td>
</tr>
<tr>
<td><code>allow_user_exec_content</code></td>
<td>Regular users to execute content from home directories</td>
</tr>
<tr>
<td><code>ftpd_anon_write</code></td>
<td>Anonymous FTP upload</td>
</tr>
<tr>
<td><code>samba_export_all_rw</code></td>
<td>Samba to export any file read/write</td>
</tr>
</tbody></table>
<hr />
<h2>Managing Port Contexts</h2>
<p>SELinux also controls which ports services are allowed to bind to. If you're running a service on a non-standard port, you need to tell SELinux about it.</p>
<pre><code class="language-bash"># List all port context mappings
semanage port -l

# Check if a specific port is labelled correctly
semanage port -l | grep 8080

# Allow httpd to bind to port 8080
semanage port -a -t http_port_t -p tcp 8080

# Modify existing port mapping
semanage port -m -t http_port_t -p tcp 8443

# Verify your change
semanage port -l | grep http_port_t
</code></pre>
<hr />
<h2>Troubleshooting SELinux Denials Like a Pro</h2>
<blockquote>
<p><em>"The first response to an SELinux denial should never be</em> <code>setenforce 0</code><em>. It should be</em> <code>ausearch -m avc -ts recent</code><em>."</em></p>
</blockquote>
<h3>Reading the Audit Logs</h3>
<pre><code class="language-bash"># View all recent AVC (Access Vector Cache) denials
ausearch -m avc -ts recent

# Stream live audit events
ausearch -m avc -ts recent -f

# View denials in the system journal
journalctl | grep "avc: denied"

# If audit daemon isn't running, check kernel messages
dmesg | grep "avc: denied"
</code></pre>
<h3>Decoding an AVC Denial Message</h3>
<p>Here's a real-world AVC denial and how to read it:</p>
<pre><code class="language-plaintext">type=AVC msg=audit(1712345678.123:456): avc:  denied  { read } for
  pid=1234 comm="nginx" name="app.conf"
  dev="sda1" ino=12345
  scontext=system_u:system_r:httpd_t:s0
  tcontext=system_u:object_r:admin_home_t:s0
  tclass=file permissive=0
</code></pre>
<p>Breaking this down:</p>
<table>
<thead>
<tr>
<th>Field</th>
<th>Meaning</th>
</tr>
</thead>
<tbody><tr>
<td><code>{ read }</code></td>
<td>The permission that was denied</td>
</tr>
<tr>
<td><code>comm="nginx"</code></td>
<td>The process that was blocked</td>
</tr>
<tr>
<td><code>scontext=...httpd_t...</code></td>
<td>Source (subject) context — nginx's type</td>
</tr>
<tr>
<td><code>tcontext=...admin_home_t...</code></td>
<td>Target (object) context — the file's type</td>
</tr>
<tr>
<td><code>tclass=file</code></td>
<td>The class of object being accessed</td>
</tr>
<tr>
<td><code>permissive=0</code></td>
<td>This was enforced (0 = enforced, 1 = permissive/logged only)</td>
</tr>
</tbody></table>
<p><strong>The fix here is clear:</strong> the nginx config file has the wrong type label (<code>admin_home_t</code> instead of <code>httpd_config_t</code>). Use <code>semanage fcontext</code> to fix the label permanently.</p>
<h3>Using audit2why and audit2allow</h3>
<pre><code class="language-bash"># audit2why explains WHY a denial happened in human-readable terms
ausearch -m avc -ts recent | audit2why

# audit2allow generates a policy module to allow the denied action
# Use carefully — understand what you're allowing before applying it
ausearch -m avc -ts recent | audit2allow

# Generate a complete installable policy module
ausearch -m avc -ts recent | audit2allow -M mypolicy

# Install the generated module
semodule -i mypolicy.pp

# List installed policy modules
semodule -l

# Remove a module
semodule -r mypolicy
</code></pre>
<blockquote>
<p>🔴 <strong>Caution with audit2allow</strong></p>
<p><code>audit2allow</code> generates policy that <em>allows</em> the denied action. Always understand what you're permitting before installing it. A mislabeled file should be <strong>relabeled</strong>, not policy-excepted.</p>
<p>Use <code>audit2allow</code> as a last resort for genuinely unusual but legitimate access patterns.</p>
</blockquote>
<h3>Troubleshooting Decision Tree</h3>
<table>
<thead>
<tr>
<th>Symptom</th>
<th>Likely Cause</th>
<th>Fix</th>
</tr>
</thead>
<tbody><tr>
<td>Service won't start, permission denied</td>
<td>Wrong file context on config/data files</td>
<td><code>restorecon -Rv /path/</code></td>
</tr>
<tr>
<td>App can't make outbound connections</td>
<td>Boolean not set</td>
<td><code>setsebool -P httpd_can_network_connect on</code></td>
</tr>
<tr>
<td>Service won't bind to custom port</td>
<td>Port not labelled for service type</td>
<td><code>semanage port -a -t TYPE -p tcp PORT</code></td>
</tr>
<tr>
<td>Files copied from elsewhere denied</td>
<td>Files inherited wrong context</td>
<td><code>semanage fcontext</code> + <code>restorecon</code></td>
</tr>
<tr>
<td>Everything worked before relabel</td>
<td>Custom context lost after relabel</td>
<td>Set policy with <code>semanage fcontext</code> (not <code>chcon</code>)</td>
</tr>
</tbody></table>
<hr />
<h2>SELinux Best Practices: Do's and Don'ts</h2>
<img src="https://cdn.hashnode.com/uploads/covers/645bd7f3d3761288bf03ed2c/6c155649-9a3e-48d8-8b9e-bb569e1be12f.png" alt="" style="display:block;margin:0 auto" />

<h2>Real-World Scenario: Deploying a Node.js App Behind Nginx</h2>
<p>You've deployed a Node.js app at <code>/opt/myapp/</code> and configured Nginx to proxy to it. After deployment, Nginx can't read the app files. Here's the SELinux-aware workflow:</p>
<pre><code class="language-bash"># Step 1: Check if SELinux is the culprit
ausearch -m avc -ts recent | grep nginx

# Step 2: Understand the denial
ausearch -m avc -ts recent | audit2why
# Output might say:
# "nginx is trying to read a file with type 'var_t'.
#  You need to change the file's type to 'httpd_sys_content_t'"

# Step 3: Fix the file context permanently
semanage fcontext -a -t httpd_sys_content_t "/opt/myapp(/.*)?"
restorecon -Rv /opt/myapp/

# Step 4: If nginx proxies to Node.js on a custom port (e.g. 3000)
semanage port -l | grep 3000
# If nothing shows — add it:
semanage port -a -t http_port_t -p tcp 3000

# Step 5: Ensure nginx is allowed to make network connections
setsebool -P httpd_can_network_connect on

# Step 6: Verify — restart nginx and check for new AVC denials
systemctl restart nginx
ausearch -m avc -ts recent
</code></pre>
<hr />
<h2>Quick Reference: Essential SELinux Commands</h2>
<table>
<thead>
<tr>
<th>Command</th>
<th>Purpose</th>
</tr>
</thead>
<tbody><tr>
<td><code>sestatus</code></td>
<td>Verbose status — mode, policy, context</td>
</tr>
<tr>
<td><code>getenforce</code></td>
<td>Current mode (one word)</td>
</tr>
<tr>
<td><code>setenforce 0 / 1</code></td>
<td>Temporarily switch Permissive / Enforcing</td>
</tr>
<tr>
<td><code>ls -lZ</code></td>
<td>View file security contexts</td>
</tr>
<tr>
<td><code>ps -eZ</code></td>
<td>View process security contexts</td>
</tr>
<tr>
<td><code>chcon -t TYPE file</code></td>
<td>Change file context (temporary)</td>
</tr>
<tr>
<td><code>semanage fcontext -a -t TYPE "path"</code></td>
<td>Add permanent context mapping</td>
</tr>
<tr>
<td><code>restorecon -Rv /path/</code></td>
<td>Apply policy-based contexts to files</td>
</tr>
<tr>
<td><code>getsebool -a</code></td>
<td>List all booleans</td>
</tr>
<tr>
<td><code>setsebool -P BOOL on/off</code></td>
<td>Set boolean permanently</td>
</tr>
<tr>
<td><code>semanage port -l</code></td>
<td>List port context mappings</td>
</tr>
<tr>
<td><code>semanage port -a -t TYPE -p tcp PORT</code></td>
<td>Add port context</td>
</tr>
<tr>
<td><code>ausearch -m avc -ts recent</code></td>
<td>View recent AVC denials</td>
</tr>
<tr>
<td><code>audit2why</code></td>
<td>Explain why a denial happened</td>
</tr>
<tr>
<td><code>audit2allow -M name</code></td>
<td>Generate installable policy module</td>
</tr>
<tr>
<td><code>semodule -i name.pp</code></td>
<td>Install a policy module</td>
</tr>
<tr>
<td><code>fixfiles -F onboot</code></td>
<td>Schedule filesystem relabel on reboot</td>
</tr>
</tbody></table>
<hr />
<h2>Summary: The SELinux Mental Model</h2>
<p>After reading this guide, here's the mental model to keep in your head:</p>
<ul>
<li><p>SELinux enforces <strong>mandatory access control</strong> at the kernel level — a safety net even root can't bypass</p>
</li>
<li><p>Everything has a <strong>label (security context)</strong> — processes, files, ports, sockets</p>
</li>
<li><p>The <strong>type field</strong> in the context is what SELinux policy mostly cares about</p>
</li>
<li><p>Use <strong>Permissive mode</strong> for debugging — never Disabled</p>
</li>
<li><p>Use <code>semanage</code> <strong>+</strong> <code>restorecon</code> for permanent, policy-backed context changes</p>
</li>
<li><p>Use <strong>booleans</strong> to toggle common behaviors without writing custom policy</p>
</li>
<li><p>Read <strong>AVC denials</strong> — they tell you exactly what process, file, and permission was blocked</p>
</li>
<li><p>Use <code>audit2why</code> to understand, <code>audit2allow</code> only as a last resort</p>
</li>
</ul>
<blockquote>
<p>Mastering SELinux isn't about memorizing commands — it's about developing the instinct to read what the kernel is telling you and responding precisely.</p>
</blockquote>
<hr />
<p><em>Have you ever debugged a production issue caused by SELinux policies? Share your experience in the comments — the community learns best from real scenarios.</em></p>
]]></content:encoded></item><item><title><![CDATA[Application load balancer Demonstration]]></title><description><![CDATA[Application Load Balancer?
A load balancer serves as the single point of contact for clients. The load balancer distributes incoming application traffic across multiple targets, such as EC2 instances, in multiple Availability Zones. This increases th...]]></description><link>https://blog.lokendrabhat.com.np/application-load-balancer-demonstration</link><guid isPermaLink="true">https://blog.lokendrabhat.com.np/application-load-balancer-demonstration</guid><category><![CDATA[AWS]]></category><category><![CDATA[AWS Applicaction Load Balancer]]></category><category><![CDATA[Load Balancing]]></category><category><![CDATA[ec2]]></category><dc:creator><![CDATA[Lokendra Bhat]]></dc:creator><pubDate>Mon, 15 Jan 2024 18:15:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1687105790083/9753c1d8-9379-4afa-803b-01434f5950f2.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-application-load-balancer"><strong>Application Load Balancer?</strong></h2>
<p>A <em>load balancer</em> serves as the single point of contact for clients. The load balancer distributes incoming application traffic across multiple targets, such as EC2 instances, in multiple Availability Zones. This increases the availability of your application. You add one or more listeners to your load balancer.</p>
<p>[ Reference Source: <a target="_blank" href="https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html">AWS documentation</a> ]</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1687099995946/58ebf270-058f-4c20-be00-10aa536af4dc.png" alt /></p>
<h2 id="heading-lets-start-the-lab-session-in-aws-account">Let's start the Lab session in AWS account</h2>
<h3 id="heading-in-this-lab-you-will-learn-the-following">In this lab you will learn the following:</h3>
<ul>
<li><p>How to create an EC2 instance with user data</p>
</li>
<li><p>How to make simple VPC</p>
</li>
<li><p>How to make a security group suit for ELB</p>
</li>
<li><p>How to configure multiple EC2 with an Application load balancer</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1687099848779/f887c695-fc91-41e8-93ba-99231812d28d.jpeg" alt class="image--center mx-auto" /></p>
<h3 id="heading-step-1-create-a-simple-vpc">Step 1: Create a Simple VPC.</h3>
<ul>
<li><p>Search VPC and create VPC as the following VPC setting:</p>
<ul>
<li><p>Resources to create: <code>VPC Only</code></p>
</li>
<li><p>Name tag <em>- optional:</em> <code>myVPC</code></p>
</li>
<li><p>IPv4 CIDR: <code>10.0.0.0/16</code></p>
</li>
<li><p>Leave all default and <strong><mark>Create VPC</mark></strong></p>
</li>
</ul>
</li>
<li><p>Select subnets and create subnets as:</p>
<ul>
<li><p>VPC ID: Select <code>myVPC</code></p>
</li>
<li><p>Subnet Settings: (for subnet1)</p>
<ul>
<li><p>Subnet name: <code>subnet1</code></p>
</li>
<li><p>Availability Zone: Select 1st zone</p>
</li>
<li><p>IPv4 CIDR block: <code>10.0.0.0/24</code></p>
</li>
</ul>
</li>
<li><p><code>Add new subnet</code></p>
</li>
<li><p>Subnet Settings: (for subnet2)</p>
<ul>
<li><p>Subnet name: <code>subnet2</code></p>
</li>
<li><p>Availability Zone: Select 2nd zone</p>
</li>
<li><p>IPv4 CIDR block: <code>10.0.1.0/24</code></p>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>    ( Note: you can add more than 2 subnets also )</p>
<p>    <strong><mark>Create subnet</mark></strong></p>
<ul>
<li><p>Create an internet gateway and attach it to VPC as:</p>
<ul>
<li><p><strong>Internet gateway settings</strong></p>
<ul>
<li><p>Name tag: <code>myIG</code></p>
<p>  <strong><mark>Create internet gateway</mark></strong></p>
</li>
</ul>
</li>
<li><p>Attach to a VPC and select <code>myVPC</code></p>
<p>  <strong><mark>Attach internet gateway</mark></strong></p>
</li>
</ul>
</li>
<li><p>Select the route table and Create the route table as:</p>
<ul>
<li><p><strong>Route table settings</strong></p>
<ul>
<li><p>Name <em>- optional:</em> <code>route</code></p>
</li>
<li><p>VPC: Select <code>myVPC</code></p>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>        <strong><mark>Create route table</mark></strong></p>
<ul>
<li><p>Select <code>route</code> ID and then go to Routes -&gt; Edit routes -&gt; Add route</p>
<ul>
<li><p><strong>Destination:</strong> <code>0.0.0.0/0</code></p>
</li>
<li><p><strong>Target:</strong> Select internet gateway and select that we created</p>
<p>  and <strong><mark>Save changes</mark></strong></p>
</li>
</ul>
</li>
<li><p>Similarly, Select <code>route</code> ID and then go to Subnet associations -&gt; Edit Subnet associations</p>
<ul>
<li>Select all subnets and <strong><mark>Save associations</mark></strong></li>
</ul>
</li>
</ul>
<h3 id="heading-step-2-create-a-security-group-for-elb">Step 2: Create a security group for ELB:</h3>
<p>Search VPC, scroll down its left sidebar and create a security group as:</p>
<ul>
<li><p>Security group name: <code>ELBsecurity</code></p>
</li>
<li><p>Description: <code>Elastic load balancer use it</code></p>
</li>
<li><p>VPC: remove existing and select <code>myVPC</code></p>
</li>
<li><p><strong>Inbound rules:</strong></p>
<ul>
<li><p>Add rule</p>
<ol>
<li><p>Type: <code>SSH</code>, Source: <code>0.0.0.0/0</code></p>
</li>
<li><p>Type: <code>HTTP</code>, Source: <code>0.0.0.0/0</code></p>
</li>
</ol>
</li>
</ul>
</li>
<li><p><strong>Outbound rules:</strong></p>
<ul>
<li>Leave default i.e. Type: <code>All traffic</code>, Source: <code>0.0.0.0/0</code></li>
</ul>
</li>
<li><p><strong><mark>Create security group</mark></strong></p>
</li>
</ul>
<h3 id="heading-step-3-create-two-ec2-instances">Step 3: Create two EC2 instances.</h3>
<ul>
<li><p>Search EC2 and Launch EC2 instance as:</p>
</li>
<li><p>For the first EC2 instance</p>
<ul>
<li><p>Name: <code>server1</code></p>
</li>
<li><p>Create a key-pair or choose any existing key.</p>
</li>
<li><p>Network Setting &gt; <code>Edit</code></p>
<ul>
<li><p>VPC: Select <code>myVPC</code></p>
</li>
<li><p>Subnet: Select <code>subnet1</code></p>
</li>
<li><p>Auto-assign public IP: <code>enable</code></p>
</li>
<li><p>Firewall: Check <code>select existing security group</code> and select <code>ELBsecurity</code> that we created</p>
</li>
</ul>
</li>
<li><p>Leave all default and Expand <strong>Advanced details</strong></p>
<ul>
<li><p>Go directly to the user data field at last and copy-paste this:</p>
<pre><code class="lang-bash">  <span class="hljs-comment">#!/bin/bash</span>
  sudo yum update -y
  sudo yum install -y httpd
  sudo systemctl start httpd
  <span class="hljs-built_in">echo</span> <span class="hljs-string">"&lt;html&gt;&lt;body&gt;&lt;h1&gt; Hello! I am server1 &lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;"</span> &gt; /var/www/html/index.html
</code></pre>
<p>  <strong><mark>Launch instance</mark></strong></p>
</li>
</ul>
</li>
</ul>
</li>
<li><p>For the second EC2 instance</p>
<ul>
<li><p>Name: <code>server2</code></p>
</li>
<li><p>Create a key pair or choose any existing key.</p>
</li>
<li><p>Network Setting &gt; <code>Edit</code></p>
<ul>
<li><p>VPC: Select <code>myVPC</code></p>
</li>
<li><p>Subnet: Select <code>subnet2</code></p>
</li>
<li><p>Auto-assign public IP: <code>enable</code></p>
</li>
<li><p>Firewall: Check <code>select existing security group</code> and select <code>ELBsecurity</code> that we created</p>
</li>
</ul>
</li>
<li><p>Leave all default and Expand <strong>Advanced details</strong></p>
<ul>
<li><p>Go directly to the user data field at last and copy-paste this:</p>
<pre><code class="lang-bash">  <span class="hljs-comment">#!/bin/bash</span>
  sudo yum update -y
  sudo yum install -y httpd
  sudo systemctl start httpd
  <span class="hljs-built_in">echo</span> <span class="hljs-string">"&lt;html&gt;&lt;body&gt;&lt;h1&gt; Hello! I am server2 &lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;"</span> &gt; /var/www/html/index.html
</code></pre>
<p>  <strong><mark>Launch instance</mark></strong></p>
</li>
</ul>
</li>
</ul>
</li>
<li><p>Also, you can check after the 2/2 check passed whether your instances are publically accessible or not by rendering their public IP in a new tab.</p>
<p>  For example, server2 public IP gives:</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1687103972704/3300524d-361e-423f-b55e-7485d799d298.jpeg" alt class="image--center mx-auto" /></p>
</li>
</ul>
<h3 id="heading-step-4-create-an-application-load-balancer">Step 4: Create an Application load balancer.</h3>
<ul>
<li><p>In the left bar of EC2 scroll down and click on <code>Load balancers</code></p>
</li>
<li><p>Click <strong><mark>Create load balancer </mark> -&gt; Application load balancer</strong> <code>Create</code></p>
</li>
<li><p>Create Application Load Balancer as:</p>
</li>
<li><p><strong>Basic configuration</strong></p>
<ul>
<li><p>Load balancer name: <code>balanceLoad</code></p>
</li>
<li><p>Leave all default</p>
</li>
</ul>
</li>
<li><p><strong>Network mapping</strong></p>
<ul>
<li><p>VPC: Select <code>myVPC</code></p>
</li>
<li><p>Mappings: Select at least two availability zones for now we have only 2 subnets of different availability zones so select both</p>
</li>
</ul>
</li>
<li><p><strong>Security groups</strong></p>
<ul>
<li>Security groups: Select <code>ELBsecurity</code> and remove the default one</li>
</ul>
</li>
<li><p><strong>Listeners and routing</strong></p>
<ul>
<li><h5 id="heading-listener-http80"><strong>Listener HTTP:80</strong></h5>
<p>  Default action: Select a target group but we don't have a target group. Our priority is to create a target group, So select <code>Create target group</code>.</p>
<p>  [you can also create a target group first and then associate at that point.]</p>
</li>
<li><p>It renders directly to the Create target group or you can select manually at the left bar of the EC2 instance just below the load balancers</p>
</li>
</ul>
</li>
</ul>
<p>    {</p>
<ul>
<li><p>Create target group as:</p>
<ul>
<li><p><strong>Specify group details:</strong></p>
<ul>
<li><p>Target group name: <code>targetELB</code></p>
</li>
<li><p>VPC: <code>myVPC</code></p>
</li>
<li><p>Protocol version: leave as HTTP1</p>
</li>
<li><p>Leave all default and <strong><mark>Next</mark></strong></p>
</li>
</ul>
</li>
<li><p><strong>Register targets</strong></p>
<ul>
<li><p>Select both available instances and Click on Ports for the selected instances: 80 and</p>
<p>  <code>Include as pending below</code></p>
</li>
<li><p>Then <strong><mark>Create target group</mark></strong></p>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>        }</p>
<ul>
<li><p>Go back to <strong>Listeners and routing, refresh, and select</strong> <code>targetELB</code></p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1687105287996/c6649df5-c1ce-440a-bc50-9082a9a36f1e.jpeg" alt class="image--center mx-auto" /></p>
</li>
</ul>
<p>    Leaving all default and <strong><mark>Create load balancer</mark></strong></p>
<h3 id="heading-step-5-render-the-dns-of-an-application-load-balancer">Step 5: Render the DNS of an Application load balancer.</h3>
<ul>
<li><p>Go to load balancer and copy the DNS name of <code>balanceLoad</code> that we created.</p>
</li>
<li><p>Open a new tab of any browser and paste it.</p>
</li>
<li><p>Now, observe by refreshing the tab how the load is distributed.</p>
</li>
</ul>
<h3 id="heading-dont-forget-to-remove-and-terminate-all-services-that-you-created-during-the-lab-session"><mark>Don't forget to remove and terminate all services that you created during the lab session.</mark></h3>
<h1 id="heading-happy-learning">Happy Learning!!!</h1>
]]></content:encoded></item><item><title><![CDATA[EC2 instance Autoscaling]]></title><description><![CDATA[In this Lab you will get the idea of the following:

Created an Amazon EC2 launch template

Created an Amazon EC2 Auto Scaling launch configuration

Configured scaling policies and created auto Scaling group to scale in and scale out the number of se...]]></description><link>https://blog.lokendrabhat.com.np/ec2-instance-autoscaling</link><guid isPermaLink="true">https://blog.lokendrabhat.com.np/ec2-instance-autoscaling</guid><category><![CDATA[AWS]]></category><category><![CDATA[autoscaling]]></category><category><![CDATA[ec2]]></category><dc:creator><![CDATA[Lokendra Bhat]]></dc:creator><pubDate>Tue, 09 Jan 2024 18:15:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1687491239508/cf420699-40e4-4033-a531-45554e65a258.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this Lab you will get the idea of the following:</p>
<ul>
<li><p>Created an Amazon EC2 launch template</p>
</li>
<li><p>Created an Amazon EC2 Auto Scaling launch configuration</p>
</li>
<li><p>Configured scaling policies and created auto Scaling group to scale in and scale out the number of servers based on variable load</p>
</li>
</ul>
<h3 id="heading-you-need-to-first-create-these-for-this-lab">You need to first create these for this lab:</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1687491105998/221e2fd3-9812-4661-8ce0-6608e5ee8b4c.jpeg" alt class="image--center mx-auto" /></p>
<ul>
<li><p>VPC with subnet 10.0.0.0/16</p>
<ul>
<li><p>For Availability Zone 1</p>
<ul>
<li><p>public subnet: 10.0.0.0/24</p>
</li>
<li><p>private subnet: 10.0.1.0/24</p>
</li>
</ul>
</li>
<li><p>For Availability Zone 2</p>
<ul>
<li><p>public subnet: 10.0.2.0/24</p>
</li>
<li><p>private subnet: 10.0.3.0/24</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p>Security Group</p>
<ul>
<li>Inbound rule: HTTP and SSH</li>
</ul>
</li>
</ul>
<p>[ Visit my previous blogs for Creating VPC and Security group if you had problem ]</p>
<h2 id="heading-lets-begin">Let's begin:</h2>
<ol>
<li>In EC2 -&gt; Load Balancing session select Load Balancers and Create load balancer Select Application load balancer</li>
</ol>
<ul>
<li><p>Basic configuration</p>
<ul>
<li><p>Load balancer name: <code>WebELB</code></p>
</li>
<li><p>Select VPC: <code>myVPC</code></p>
</li>
<li><p>Mappings: <code>Select at least two AG so select both public subnets of different AG</code></p>
</li>
</ul>
</li>
<li><p>Security groups</p>
<ul>
<li>Security group: Select that you created to access HTTP</li>
</ul>
</li>
<li><p>Listener and routing</p>
<ul>
<li><p>Protocol: HTTP Port: 80</p>
</li>
<li><p>Create target group as:</p>
<ul>
<li><p>Target group name: <code>web-app</code></p>
</li>
<li><p>VPC: <code>myVPC</code></p>
<p>  Next</p>
</li>
<li><p>Register the targets session leave it as default and</p>
<p>  <strong><mark>Create target group</mark></strong></p>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>-Go back to the load balancer tab, refresh, and select the target group that you created</p>
<ol>
<li>Creating a launch template</li>
</ol>
<ul>
<li><p>In the EC2 left bar there is an instances section in which Launch Templates also select and create launch templates as:</p>
<ul>
<li><p>Launch template name: <code>webtemp</code></p>
</li>
<li><p>Template version description: <code>For autoscaling use</code></p>
</li>
<li><p>Select <code>Provide guidance to help me set up a template that I can use with EC2 Auto Scaling</code></p>
</li>
<li><p>Application and OS Images: select <code>My AMIs</code> and leave the default option</p>
</li>
<li><p>Instance type: <code>t3.micro</code> or other free tiers if exits</p>
</li>
<li><p>Key pait(login)-&gt; Key pair name: <code>don't include in the launch template</code></p>
</li>
<li><p>Network Settings-&gt; Subnet: <code>Don't include in launch template</code> Firewall(security group): Select the existing security group and select that you created for HTTP access</p>
</li>
<li><p>Leave all defaults and <strong><mark>Create launch template</mark></strong></p>
</li>
</ul>
</li>
</ul>
<ol>
<li>Creating an Auto Scaling group</li>
</ol>
<ul>
<li><p>Choose the Launch template that we created and From <code>Action</code> dropdown select Create Auto Scaling group</p>
<ul>
<li><p>Name -&gt;</p>
<ul>
<li><p>Auto Scaling group name: <code>Web Auto Scaling Group</code></p>
</li>
<li><p>All Default and <code>Next</code></p>
</li>
</ul>
</li>
<li><p>Network -&gt;</p>
<ul>
<li><p>VPC: <code>myVPC</code></p>
</li>
<li><p>Availability Zones and subnets: <code>Select both private subnets</code></p>
</li>
<li><p>Choose <code>Next</code></p>
</li>
</ul>
</li>
<li><p>Load balancing -&gt;</p>
<ul>
<li><p>Select Attach to an existing load balancer</p>
<ul>
<li>Existing load balancer target groups: Select <code>web-app</code> that you created</li>
</ul>
</li>
<li><p>Health checks:- Select <code>Turn on Elastic Load Balancing health checks</code></p>
</li>
<li><p>Choose <code>Next</code></p>
</li>
</ul>
</li>
<li><p>Configure group Size and scaling policies - optional</p>
<ul>
<li><p>-&gt; Group size - optional</p>
<ul>
<li><p>Desired capacity: <code>2</code></p>
</li>
<li><p>Minimum capacity: <code>2</code></p>
</li>
<li><p>Maximum capacity: <code>4</code></p>
</li>
</ul>
</li>
<li><p>-&gt; Scaling policies - optional</p>
<ul>
<li><p>Select Target tracking scaling policy</p>
<ul>
<li><p>Metric type: choose <code>Average CPU utilization</code></p>
</li>
<li><p>Target value: <code>50</code></p>
</li>
<li><p>Choose <code>Next</code></p>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><p>Add notifications - optional</p>
<ul>
<li>Choose <code>Next</code></li>
</ul>
</li>
<li><p>Add tags - optional</p>
<ul>
<li>Choose Add tag Key: Name Value-optional: <code>WebApp</code></li>
</ul>
</li>
<li><p>Review and <strong><mark>Create Auto Scaling group</mark></strong></p>
</li>
</ul>
</li>
</ul>
<ol>
<li>Verify autoscaling</li>
</ol>
<ul>
<li><p>Select instances and you see there are 2 <code>WebApp</code> named instances are automatically created</p>
</li>
<li><p>Select Target Groups and select that you created above and observe health status -&gt; healthy</p>
</li>
</ul>
<ol>
<li>Test auto-scaling configuration</li>
</ol>
<ul>
<li>When the Load of CPU utilization reaches 50%+ after a few minutes you should see your auto-scaling group add a new instance. This occurs because Amazon CloudWatch detected that the average CPU utilization of your Auto Scaling group exceeds 50% and your scale-up policy has been invoked in response. The maximum of 4 instances of name WebApp created according to policy. You can add more if needed.</li>
</ul>
<h2 id="heading-have-a-great-day">Have a great day!!!</h2>
]]></content:encoded></item><item><title><![CDATA[Linux File System]]></title><description><![CDATA[The Linux file system is a hierarchical structure that organizes data on a Linux system. It follows the Filesystem Hierarchy Standard (FHS), which defines the directory structure and the purpose of each directory.
Following are some important directo...]]></description><link>https://blog.lokendrabhat.com.np/linux-file-system</link><guid isPermaLink="true">https://blog.lokendrabhat.com.np/linux-file-system</guid><category><![CDATA[Linux]]></category><category><![CDATA[file system]]></category><dc:creator><![CDATA[Lokendra Bhat]]></dc:creator><pubDate>Tue, 09 Jan 2024 14:03:25 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1704808711229/a02d5339-2d93-4ecd-8887-ec4610061a4e.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The Linux file system is a hierarchical structure that organizes data on a Linux system. It follows the Filesystem Hierarchy Standard (FHS), which defines the directory structure and the purpose of each directory.</p>
<p>Following are some important directories in Linux:</p>
<ol>
<li><p><strong>/ (Root Directory):</strong> The top-level directory and the starting point of the file system hierarchy.</p>
</li>
<li><p><strong>/bin (Binary):</strong> Essential command binaries (programs) required for system boot and repair. This host commands executable files like ls, pwd, etc.</p>
</li>
<li><p><strong>/boot:</strong> Contains the kernel and files needed for the initial stages of the boot process.</p>
</li>
<li><p><strong>/dev (Device):</strong> Device files representing hardware devices on the system. Files having information about hardware devices.</p>
</li>
<li><p><strong>/etc (Etcetera):</strong> Configuration files and scripts needed to boot the system and configure various applications. Important for system users and DevOps.</p>
</li>
<li><p><strong>/home:</strong> Home directories for regular users.</p>
</li>
<li><p><strong>/lib (Library):</strong> Essential shared libraries and kernel modules.</p>
</li>
<li><p><strong>/media:</strong> Mount points for removable media such as USB drives or external hard disks.</p>
</li>
<li><p><strong>/mnt (Mount):</strong> Mount points for temporarily mounted file systems.</p>
</li>
<li><p><strong>/opt (Optional):</strong> Optional software packages.</p>
</li>
<li><p><strong>/proc:</strong> A virtual file system that provides information about processes and system resources.</p>
</li>
<li><p><strong>/root:</strong> Home directory for the root user.</p>
</li>
<li><p><strong>/run:</strong> Temporary files created by system processes.</p>
</li>
<li><p><strong>/sbin (System Binary):</strong> Essential system binaries used for system administration.</p>
</li>
<li><p><strong>/srv (Service):</strong> Data for services provided by the system.</p>
</li>
<li><p><strong>/sys:</strong> A virtual file system that exposes kernel parameters and information about devices, buses, and other kernel components.</p>
</li>
<li><p><strong>/tmp (Temporary):</strong> Temporary files that are deleted upon reboot.</p>
</li>
<li><p><strong>/usr (User):</strong> Secondary hierarchy containing user documentation, games, and other non-essential utilities.</p>
</li>
<li><p><strong>/var (Variable):</strong> Variable data such as log files, spool directories, and temporary files.</p>
</li>
</ol>
]]></content:encoded></item><item><title><![CDATA[Amazon SNS]]></title><description><![CDATA[Amazon Simple Notification Service (Amazon SNS) sends notifications in two ways, A2A and A2P. A2A provides high-throughput, push-based, many-to-many messaging between distributed systems, microservices, and event-driven serverless applications. These...]]></description><link>https://blog.lokendrabhat.com.np/amazon-sns</link><guid isPermaLink="true">https://blog.lokendrabhat.com.np/amazon-sns</guid><category><![CDATA[AWS]]></category><category><![CDATA[AWS SNS]]></category><dc:creator><![CDATA[Lokendra Bhat]]></dc:creator><pubDate>Thu, 28 Dec 2023 18:15:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1686556788708/7e45b11a-f4e2-49cd-bb8e-c2dabb50b4eb.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Amazon Simple Notification Service (Amazon SNS) sends notifications in two ways, A2A and A2P. A2A provides high-throughput, push-based, many-to-many messaging between distributed systems, microservices, and event-driven serverless applications. These applications include Amazon Simple Queue Service (SQS), Amazon Kinesis Data Firehose, AWS Lambda, and other HTTPS endpoints. A2P functionality lets you send messages to your customers with SMS texts, push notifications, and email. </p>
<h2 id="heading-how-to-work-with-sns-lets-make-it-easy">How to work with SNS? Let's make it easy!</h2>
<p>Here is a simple example, in which we are going to set an email alert if there are any changes in our EC2 instance.</p>
<h3 id="heading-step-1-configure-amazon-sns">Step 1: <strong>Configure Amazon SNS</strong></h3>
<ol>
<li><p>Search SNS and select it</p>
</li>
<li><p>Goto <code>Topics</code> on left bar</p>
</li>
<li><p>Click on <strong><mark>Create topic</mark></strong></p>
<ul>
<li><p>Select type <code>Standard</code></p>
</li>
<li><p>Name: <code>EmailAlert</code></p>
</li>
<li><p>Leave all default and <code>Create topic</code></p>
</li>
</ul>
</li>
<li><p>Goto <code>subscriptions</code> and select <strong><mark>Create subscription</mark></strong></p>
<ul>
<li><p>In Details Setting</p>
<ul>
<li><p>Topic: Select <code>EmailAlert</code></p>
</li>
<li><p>Protocol: Select <code>Email</code></p>
</li>
<li><p>Endpoint: <code>your-email-address</code></p>
</li>
</ul>
</li>
<li><p><code>Create subscription</code></p>
</li>
</ul>
</li>
<li><p>Now, Open your email, select the AWS Notification email and</p>
<p> select <code>Confirm subscription</code></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1686548914316/94ae9da9-75d7-4fab-935e-96e54bc1d22f.jpeg" alt class="image--center mx-auto" /></p>
</li>
</ol>
<h3 id="heading-step-2-config-amazon-eventbridge">Step 2: Config Amazon EventBridge</h3>
<h3 id="heading-another-form-of-cloudwatch">(Another form of CloudWatch)</h3>
<p>EventBridge is a serverless service that uses events to connect application components together, making it easier for you to build scalable event-driven applications. Use it to route events from sources such as home-grown applications, AWS services, and third-party software to consumer applications across your organization. EventBridge provides a simple and consistent way to ingest, filter, transform, and deliver events so you can build new applications quickly.</p>
<ol>
<li><p>Search EventBridge on the search bar and select it, Also click on Buses to expand</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1686555079129/ebf435ec-02c1-418c-a123-e57054743a31.jpeg" alt class="image--center mx-auto" /></p>
</li>
<li><p>Click on <code>Rules</code> then scroll down and click <code>Create rule</code></p>
</li>
<li><p>Configure <code>Step1: Define rule detail</code> as:</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1686555277757/8d9d4207-8fcd-478f-84de-9eca007542da.jpeg" alt class="image--center mx-auto" /></p>
</li>
<li><p>Configure <code>Step 2: Build event pattern</code> as:</p>
<ul>
<li><p>Leave all defaults and scroll down to <code>Event pattern</code></p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1686555545981/cc0e7490-c3b6-4beb-8406-d70d9be62732.jpeg" alt class="image--center mx-auto" /></p>
<p>  [ Don't panic: Select AWS service then Event type auto-generate ]</p>
</li>
</ul>
</li>
<li><p>Configure <code>Step 3: Select target(s)</code> as:</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1686555769114/b880efdf-d548-4b79-91ea-5f9d406895b4.jpeg" alt class="image--center mx-auto" /></p>
</li>
<li><p>Leave optional <code>Step 4: optional Configure tags</code></p>
</li>
<li><p><code>Step 5: Review and create</code> click on <strong><mark>Create rule</mark></strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1686555897619/80fc7bd5-eb76-452a-ae99-afe19e164673.jpeg" alt class="image--center mx-auto" /></p>
</li>
</ol>
<h3 id="heading-step-3-working-with-the-ec2-state">Step 3: Working with the EC2 state</h3>
<ul>
<li><p>In the EC2 instance anything you do with instance i.e. Create, stop, Terminate you will receive an alert email.</p>
</li>
<li><p>For example, let's launch an EC2 instance without any special setup only with the name and existing key leaving all default.</p>
</li>
<li><p>You receive an email like this:</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1686556504295/adee7ce4-5880-4fe7-8491-9d9175148ce5.jpeg" alt class="image--center mx-auto" /></p>
</li>
</ul>
<p>Don't forget to terminate all the things you created !!!</p>
<h1 id="heading-thanks-for-learning-the-sns-config">Thanks for Learning the SNS config...</h1>
]]></content:encoded></item><item><title><![CDATA[Setup MongoDB for Node project]]></title><description><![CDATA[Go to https://www.mongodb.com and click Try Free button

Click on signup with Google or fill out the given form and accept permission

Fill in the answer to all questions { you can select any options according to your own thought}

You can see an int...]]></description><link>https://blog.lokendrabhat.com.np/setup-mongodb-for-node-project</link><guid isPermaLink="true">https://blog.lokendrabhat.com.np/setup-mongodb-for-node-project</guid><category><![CDATA[MongoDB]]></category><category><![CDATA[setup]]></category><dc:creator><![CDATA[Lokendra Bhat]]></dc:creator><pubDate>Fri, 24 Nov 2023 12:25:55 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1700828716959/67d8d6fd-79df-4d4d-a75e-e2364ed48b91.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<ol>
<li><p>Go to <a target="_blank" href="https://www.mongodb.com/">https://www.mongodb.com</a> and click <code>Try Free</code> button</p>
</li>
<li><p>Click on signup with Google or fill out the given form and accept permission</p>
</li>
<li><p>Fill in the answer to all questions { you can select any options according to your own thought}</p>
</li>
<li><p>You can see an interface like this</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700824652291/21085d75-7d25-4c49-a7d0-70c7a37a3d25.jpeg" alt class="image--center mx-auto" /></p>
<p> Click on <code>Create</code> button to create a new deployment environment</p>
</li>
<li><p>Select <code>M0 FREE</code> database package as shown below:</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700824702215/17434788-400d-449e-9e5c-461c2424ad70.jpeg" alt class="image--center mx-auto" /></p>
<p> You can also select other Region for better performance</p>
<p> Give the Name of your Cluster, then click <code>Create</code></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700824749128/7ecf8b1d-b8c0-49b3-bb32-d721214b4086.jpeg" alt /></p>
</li>
<li><p>Also, please Create a username and Password of your choice, copy the password, and save it to Notepad for further use</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700825053978/30180beb-e305-484f-a22e-cd5e99c128a7.jpeg" alt class="image--center mx-auto" /></p>
<p> After copying click on <code>Create User</code> button</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700825164740/e446f8c4-9e68-4414-b686-0f2b141190e3.jpeg" alt class="image--center mx-auto" /></p>
<p> Here click <code>Add My Current IP Address</code> and then <code>Finish and Close</code></p>
</li>
<li><p>After some time your Cluster will be ready and look like when you click <code>Database</code> at the left bar</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700825980048/475ddb12-408e-4e92-8a64-14467db144f9.jpeg" alt class="image--center mx-auto" /></p>
</li>
<li><p>After that Click <code>Connect</code> and do following</p>
<ul>
<li><p>Click <code>MongoDB for VS Code</code></p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700826523026/1a9876bc-313a-4b91-b272-b49e865f7932.jpeg" alt /></p>
</li>
<li><p>Copy the marked command and close the terminal</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700826583900/2e92c501-845a-4c85-8232-e9c3293f61b8.jpeg" alt class="image--center mx-auto" /></p>
</li>
</ul>
</li>
<li><p>Now open the VS code and go to the Extensions to download</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700826007383/ee6f728c-90cc-4ff7-af7e-66159dfb0e68.jpeg" alt class="image--center mx-auto" /></p>
</li>
<li><p>Now you can see the symbol of MongoDB at the left sidebar</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700826786523/951e1775-7ebc-45eb-bfc8-bcf2507737d9.jpeg" alt class="image--center mx-auto" /></p>
<ul>
<li><p>Click <code>Add Connection</code> -&gt; then <code>Connect</code></p>
</li>
<li><p>Paste the copied command from above and replace &lt;password&gt;, then the new command looks like the following</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700827492520/54ba3f94-e8e5-478b-9607-d4f2c5b6a71f.jpeg" alt class="image--center mx-auto" /></p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700827620141/6e93fc74-3f41-4aa0-9993-75983f92f77d.jpeg" alt class="image--center mx-auto" /></p>
<p>  Press enter. MongoDB connected Successfully</p>
</li>
</ul>
</li>
<li><p>Create Database</p>
<ul>
<li><p>Click <code>(+)</code> icon and it automatically opens a file</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700827743254/c11bde66-43bf-4599-bdf5-4d894f00da0b.jpeg" alt /></p>
</li>
<li><p>Edit the file as follows and run by pressing the play button at the top right corner</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700827899224/bbb68cb7-5e9e-4a8f-ae14-5fc4aefb6da8.jpeg" alt class="image--center mx-auto" /></p>
</li>
</ul>
</li>
</ol>
<p>Now you can use MongoDB with ease.</p>
<h1 id="heading-thanks-for-your-time"><mark>THANKS </mark> <strong><mark>FOR </mark></strong> <mark>YOUR TIME</mark></h1>
]]></content:encoded></item><item><title><![CDATA[How to give the user sudo privilege?]]></title><description><![CDATA[Scenario: Create two users 'tom' and 'cat'. 'tom' must have sudo privilege whereas 'cat' has normal privilege. Also, a file created by 'tom' is editable by 'cat'. 'tom' must have a home directory /home/tom but the 'cat' should not have a home directo...]]></description><link>https://blog.lokendrabhat.com.np/how-to-give-the-user-sudo-privilege</link><guid isPermaLink="true">https://blog.lokendrabhat.com.np/how-to-give-the-user-sudo-privilege</guid><category><![CDATA[Linux]]></category><dc:creator><![CDATA[Lokendra Bhat]]></dc:creator><pubDate>Mon, 02 Oct 2023 13:29:04 GMT</pubDate><content:encoded><![CDATA[<p><strong>Scenario:</strong> Create two users '<strong>tom'</strong> and '<strong>cat'</strong>. 't<strong>om'</strong> must have sudo privilege whereas '<strong>cat'</strong> has normal privilege. Also, a file created by '<strong>tom'</strong> is editable by '<strong>cat'</strong>. '<strong>tom'</strong> must have a home directory <strong>/home/tom</strong> but the 'cat' should not have a home directory.</p>
<ol>
<li><p>Switch to root user:</p>
<pre><code class="lang-bash"> sudo su
</code></pre>
</li>
<li><p>Create users ‘tom’ and ‘cat’ as</p>
<pre><code class="lang-bash"> adduser tom
 adduser cat
 tail -n 5 /etc/passwd
</code></pre>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696252583451/05a6b93a-9179-48d9-a262-24b21363dab4.jpeg" alt class="image--center mx-auto" /></p>
</li>
<li><p>Add sudo privilege configuration for user tom</p>
<pre><code class="lang-bash"> sudo visudo
</code></pre>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696252723774/9e5886f1-7079-4820-97d9-395e566d8c3e.jpeg" alt class="image--center mx-auto" /></p>
<p> Save and exit.</p>
</li>
<li><p>Now remove the default created home directory of 'cat' user so that 'cat' user should not have any home directory using the root user</p>
<pre><code class="lang-bash"> sudo rm -rf cat
 su cat
 <span class="hljs-built_in">cd</span>
 ls
</code></pre>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696252835160/e5b41b4d-e076-4591-9275-6462d103df6a.jpeg" alt class="image--center mx-auto" /></p>
<ol>
<li><p>Now create a file using user 'tom'</p>
<pre><code class="lang-bash"> su tom
 cat &gt; hello.txt
</code></pre>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696253022071/1c37f763-5268-4ebb-98c1-54216320cd6c.jpeg" alt class="image--center mx-auto" /></p>
</li>
</ol>
<p>Change ownership so that cat user can access the current folder and content.</p>
<pre><code class="lang-bash">sudo chown cat .
su cat
</code></pre>
<p>So we can access and edit it from cat user</p>
<pre><code class="lang-bash">nano hello.txt
cat hello.txt
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696253132989/48dfc2f5-aab9-4b6c-8419-316a465e31c6.jpeg" alt class="image--center mx-auto" /></p>
<p>Now we are able to access files and folders inside /home/tom with cat user also.</p>
]]></content:encoded></item><item><title><![CDATA[Intra-region Vs Inter-region Vpc Peering Connection]]></title><description><![CDATA[Intra-Region VPC peering:
Intra-region VPC peering means the VPC peering connection between different VPCs within the same region.
Inter-Region VPC peering:
Inter-region VPC peering is the VPC connection between different VPCs of different regions.

...]]></description><link>https://blog.lokendrabhat.com.np/intra-region-vs-inter-region-vpc-peering-connection</link><guid isPermaLink="true">https://blog.lokendrabhat.com.np/intra-region-vs-inter-region-vpc-peering-connection</guid><category><![CDATA[vpc]]></category><category><![CDATA[vpc peering]]></category><category><![CDATA[architecture]]></category><dc:creator><![CDATA[Lokendra Bhat]]></dc:creator><pubDate>Mon, 03 Jul 2023 16:07:44 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1688400347057/a1c0a229-3138-403f-92eb-8568f354f52d.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-intra-region-vpc-peering">Intra-Region VPC peering:</h3>
<p>Intra-region VPC peering means the VPC peering connection between different VPCs within the same region.</p>
<h3 id="heading-inter-region-vpc-peering">Inter-Region VPC peering:</h3>
<p>Inter-region VPC peering is the VPC connection between different VPCs of different regions.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1688400374623/c7c8c5f9-7fa5-4692-bd86-a220a94b264a.jpeg" alt class="image--center mx-auto" /></p>
<p>In VPC peering we have to connect all of these with each other to connect since VPC does not support transition property as shown in the figure above.</p>
<p>In this lab, the following terms are considered:</p>
<ul>
<li><p>we are going to create 3 VPCs, 2 in the same region for intra-region connection and one in a different region for inter-region connection.</p>
</li>
<li><p>Create at least one public subnet for now for each VPC for creating EC2 instance using that VPC</p>
</li>
<li><p>EC2 is used to check whether the connection is established or not using the internet gateway and ssh.</p>
</li>
</ul>
<h3 id="heading-architecture-for-lab">Architecture for LAB:</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1688390683351/dbcccb72-6931-44e9-9450-4e72524ec980.jpeg" alt class="image--center mx-auto" /></p>
<h3 id="heading-step-1-create-two-vpcs-using-the-configuration-in-any-one-region">Step 1: Create two VPCs using the configuration in any one region:</h3>
<ul>
<li><p><strong>Open your account and select</strong> <code>us-east-1</code> <strong>any other region</strong></p>
</li>
<li><p><strong>Goto VPC and then create two VPCs</strong></p>
</li>
</ul>
<p><strong>For VPC1:</strong></p>
<ul>
<li><p>Your VPCs: VPC settings:</p>
<ul>
<li><p>Select Resources to create <code>VPC only</code></p>
</li>
<li><p>Name tag <em>- optional:</em> <code>VPC1</code></p>
</li>
<li><p>IPv4 CIDR: <code>10.0.0.0/16</code></p>
<p>  <strong><mark>Create VPC</mark></strong></p>
</li>
</ul>
</li>
<li><p>Subnets: Create subnet</p>
<ul>
<li><p>VPC ID: select <code>VPC1</code></p>
</li>
<li><p>Subnet name: <code>vpc1subnet</code></p>
</li>
<li><p>Availability Zone: <code>us-east-1a</code> or any other as your choice</p>
</li>
<li><p>IPv4 CIDR block: <code>10.0.0.0/24</code></p>
<p>  <strong><mark>Create subnet</mark></strong></p>
</li>
</ul>
</li>
<li><p>Internet gateways: Create Internet gateway</p>
<ul>
<li><p>Name tag: <code>vpc1gateway</code></p>
<p>  <strong><mark>Create internet gateway</mark></strong></p>
</li>
<li><p>Attach to VPC: Select <code>VPC1</code></p>
</li>
</ul>
</li>
<li><p>Route tables: Create route table</p>
<ul>
<li><p>Name <em>- optional:</em> <code>vpc1route</code></p>
</li>
<li><p>VPC: Select <code>VPC1</code></p>
<p>  <strong><mark>Create route table</mark></strong></p>
</li>
<li><p>Select <code>vpc1route ID</code> -&gt; Select <code>Routes</code> -&gt; <code>Edit route</code> -&gt; <code>Add route</code></p>
<ul>
<li><p><strong>Destination:</strong> <code>0.0.0.0/0</code> <strong>Target:</strong> select internet gateway and then <code>vpc1gateway</code></p>
<p>  <strong><mark>Save changes</mark></strong></p>
</li>
</ul>
</li>
<li><p>Select <code>vpc1route ID</code> -&gt; Select <code>Subnet associations</code>-&gt;</p>
<p>  <code>Edit subnet associations</code></p>
<ul>
<li>Select <code>vpc1subnet</code> and <strong><mark>Save associations</mark></strong></li>
</ul>
</li>
</ul>
</li>
</ul>
<p><strong>For VPC2: (in the same region</strong> <code>us-east-1</code><strong>)</strong></p>
<ul>
<li><p>Your VPCs: VPC settings:</p>
<ul>
<li><p>Select Resources to create <code>VPC only</code></p>
</li>
<li><p>Name tag <em>- optional:</em> <code>VPC2</code></p>
</li>
<li><p>IPv4 CIDR: <code>20.0.0.0/16</code></p>
<p>  <strong><mark>Create VPC</mark></strong></p>
</li>
</ul>
</li>
<li><p>Subnets: Create subnet</p>
<ul>
<li><p>VPC ID: select <code>VPC2</code></p>
</li>
<li><p>Subnet name: <code>vpc2subnet</code></p>
</li>
<li><p>Availability Zone: <code>us-east-1a</code> or any other as your choice</p>
</li>
<li><p>IPv4 CIDR block: <code>20.0.0.0/24</code></p>
<p>  <strong><mark>Create subnet</mark></strong></p>
</li>
</ul>
</li>
<li><p>Internet gateways: Create Internet gateway</p>
<ul>
<li><p>Name tag: <code>vpc2gateway</code></p>
<p>  <strong><mark>Create internet gateway</mark></strong></p>
</li>
<li><p>Attach to VPC: Select <code>VPC2</code></p>
</li>
</ul>
</li>
<li><p>Route tables: Create route table</p>
<ul>
<li><p>Name <em>- optional:</em> <code>vpc2route</code></p>
</li>
<li><p>VPC: Select <code>VPC2</code></p>
<p>  <strong><mark>Create route table</mark></strong></p>
</li>
<li><p>Select <code>vpc2route ID</code> -&gt; Select <code>Routes</code> -&gt; <code>Edit route</code> -&gt; <code>Add route</code></p>
<ul>
<li><p><strong>Destination:</strong> <code>0.0.0.0/0</code> <strong>Target:</strong> select internet gateway and then <code>vpc2gateway</code></p>
<p>  <strong><mark>Save changes</mark></strong></p>
</li>
</ul>
</li>
<li><p>Select <code>vpc2route ID</code> -&gt; Select <code>Subnet associations</code>-&gt;</p>
<p>  <code>Edit subnet associations</code></p>
<ul>
<li>Select <code>vpc2subnet</code> and <strong><mark>Save associations</mark></strong></li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="heading-step-2-create-ec2-instances-for-individual-vpcs">Step 2: Create EC2 instances for individual VPCs</h3>
<p><strong>FOR first EC2 using VPC1</strong></p>
<ul>
<li><p>Search and open EC2</p>
</li>
<li><p>Select Instances and Launch instances</p>
<ul>
<li><p>Name: <code>vpc1server</code></p>
</li>
<li><p>Key pair name <em>- required:</em> <code>Create new key pair</code></p>
<p>  Key pair name: <code>myk</code></p>
<p>  For putty select .ppk and for Linux or ssh select .pem</p>
</li>
<li><p>Expand Network settings and <code>EDIT</code> as</p>
<ul>
<li><p>VPC <em>- required: Select</em> <code>VPC1</code></p>
</li>
<li><p>Subnet: Select <code>vpc1subnet</code></p>
</li>
<li><p>Auto-assign public IP: <code>Enable</code></p>
</li>
<li><p><strong>Firewall (security groups): Select</strong> <code>Create security group</code></p>
<p>  (Note: You can individually create SG)</p>
<ul>
<li><p>Security group name <em>- required:</em> <code>Region1SG</code></p>
</li>
<li><p>Description <em>- required:</em> <code>Its for VPC1 in region 1</code></p>
</li>
<li><p>Inbound Security Group Rules</p>
<ul>
<li><p>Add security group rule:</p>
<p>  Type: <code>All ICMP - IPv4</code></p>
<p>  Source type: <code>Anywhere</code></p>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>        <strong><mark>Launch instances</mark></strong></p>
<p><strong>FOR second EC2 using VPC2</strong></p>
<ul>
<li><p>Search and open EC2</p>
</li>
<li><p>Select Instances and Launch instances</p>
<ul>
<li><p>Name: <code>vpc2server</code></p>
</li>
<li><p>Key pair name <em>- required:</em> <code>Create new key pair</code> or Select <code>myk</code> created above</p>
<p>  For putty select .ppk and for Linux or ssh select .pem</p>
</li>
<li><p>Expand Network settings and <code>EDIT</code> as</p>
<ul>
<li><p>VPC <em>- required: Select</em> <code>VPC2</code></p>
</li>
<li><p>Subnet: Select <code>vpc2subnet</code></p>
</li>
<li><p>Auto-assign public IP: <code>Enable</code></p>
</li>
<li><p><strong>Firewall (security groups): Select</strong> <code>Create security group</code></p>
<p>  (Note: You can individually create SG)</p>
<ul>
<li><p>Security group name <em>- required:</em> <code>Region1SG2</code></p>
</li>
<li><p>Description <em>- required:</em> <code>Its for VPC2 in region 1</code></p>
</li>
<li><p>Inbound Security Group Rules</p>
<ul>
<li><p>Add security group rule:</p>
<p>  Type: <code>All ICMP - IPv4</code></p>
<p>  Source type: <code>Anywhere</code></p>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>        <strong><mark>Launch instances</mark></strong></p>
<h3 id="heading-all-done-for-region-1">All Done for Region 1</h3>
<hr />
<h3 id="heading-step-3-create-vpc-in-another-region-as">Step 3: Create VPC in another region as</h3>
<p><strong>For VPC3: Change region as</strong> <code>us-west-2</code> <strong>or any other region</strong></p>
<ul>
<li><p>Your VPCs: VPC settings:</p>
<ul>
<li><p>Select Resources to create <code>VPC only</code></p>
</li>
<li><p>Name tag <em>- optional:</em> <code>VPC3</code></p>
</li>
<li><p>IPv4 CIDR: <code>30.0.0.0/16</code></p>
<p>  <strong><mark>Create VPC</mark></strong></p>
</li>
</ul>
</li>
<li><p>Subnets: Create subnet</p>
<ul>
<li><p>VPC ID: select <code>VPC3</code></p>
</li>
<li><p>Subnet name: <code>vpc3subnet</code></p>
</li>
<li><p>Availability Zone: <code>us-west-1a</code> or any other as your choice</p>
</li>
<li><p>IPv4 CIDR block: <code>30.0.0.0/24</code></p>
<p>  <strong><mark>Create subnet</mark></strong></p>
</li>
</ul>
</li>
<li><p>Internet gateways: Create Internet gateway</p>
<ul>
<li><p>Name tag: <code>vpc3gateway</code></p>
<p>  <strong><mark>Create internet gateway</mark></strong></p>
</li>
<li><p>Attach to VPC: Select <code>VPC3</code></p>
</li>
</ul>
</li>
<li><p>Route tables: Create route table</p>
<ul>
<li><p>Name <em>- optional:</em> <code>vpc3route</code></p>
</li>
<li><p>VPC: Select <code>VPC3</code></p>
<p>  <strong><mark>Create route table</mark></strong></p>
</li>
<li><p>Select <code>vpc3route ID</code> -&gt; Select <code>Routes</code> -&gt; <code>Edit route</code> -&gt; <code>Add route</code></p>
<ul>
<li><p><strong>Destination:</strong> <code>0.0.0.0/0</code> <strong>Target:</strong> select internet gateway and then <code>vpc3gateway</code></p>
<p>  <strong><mark>Save changes</mark></strong></p>
</li>
</ul>
</li>
<li><p>Select <code>vpc3route ID</code> -&gt; Select <code>Subnet associations</code>-&gt;</p>
<p>  <code>Edit subnet associations</code></p>
<ul>
<li>Select <code>vpc3subnet</code> and <strong><mark>Save associations</mark></strong></li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="heading-step-4-create-an-ec2-instance-for-vpc-in-that-region">Step 4: Create an EC2 instance for VPC in that region</h3>
<p><strong>FOR EC2 using VPC3</strong></p>
<ul>
<li><p>Search and open EC2</p>
</li>
<li><p>Select Instances and Launch instances</p>
<ul>
<li><p>Name: <code>vpc3server</code></p>
</li>
<li><p>Key pair name <em>- required:</em> <code>Create new key pair</code></p>
<p>  Key pair name: <code>mykey3</code></p>
<p>  For putty select .ppk and for Linux or ssh select .pem</p>
</li>
<li><p>Expand Network setting and <code>EDIT</code> as</p>
<ul>
<li><p>VPC <em>- required: Select</em> <code>VPC3</code></p>
</li>
<li><p>Subnet: Select <code>vpc3subnet</code></p>
</li>
<li><p>Auto-assign public IP: <code>Enable</code></p>
</li>
<li><p><strong>Firewall (security groups): Select</strong> <code>Create security group</code></p>
<p>  (Note: You can individually create SG)</p>
<ul>
<li><p>Security group name <em>- required:</em> <code>Region2SG3</code></p>
</li>
<li><p>Description <em>- required:</em> <code>Its for VPC3 in region 2</code></p>
</li>
<li><p>Inbound Security Group Rules</p>
<ul>
<li><p>Add security group rule:</p>
<p>  Type: <code>All ICMP - IPv4</code></p>
<p>  Source type: <code>Anywhere</code></p>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>        <strong><mark>Launch instances</mark></strong></p>
<h3 id="heading-step-5-connect-to-any-initial-server">Step 5: Connect to any initial server</h3>
<ul>
<li><p><strong>Change the region:</strong> <code>us-east-1</code></p>
</li>
<li><p>Select the <code>vpc1server</code> and copy <code>Public IPv4 address</code></p>
</li>
<li><p><strong>For window user</strong></p>
<ul>
<li><p>Download and Open Putty and in session:</p>
<ul>
<li>Host Name (or IP address): paste <code>Public IPv4 address</code></li>
</ul>
</li>
<li><p>In left Expand <code>+Connection</code> -&gt; Expand <code>+SSH</code> -&gt; Expand <code>+Auth</code> -&gt; Credentials</p>
<ul>
<li>Private key file for authentication: browse and choose <code>myk.ppk</code> that automatically downloaded while creating key pair</li>
</ul>
</li>
<li><p>Click <code>Open</code></p>
</li>
<li><p>Accept if any alert box appears and login as: <code>ec2-user</code> in your case enter the IAM username to connect</p>
</li>
</ul>
</li>
<li><p><strong>For Linux user</strong></p>
<ul>
<li><p>Open <code>Bash terminal</code> and go to the directory where you want to perform the SSH command</p>
</li>
<li><p>Locate the key pair that downloaded automatically while creating as <code>myk.pem</code> and move to that directory</p>
</li>
<li><p>Then paste the following code:</p>
</li>
</ul>
</li>
</ul>
<pre><code class="lang-bash">    ssh -i <span class="hljs-string">"myk.pem"</span> &lt;IAM-user-name&gt;@&lt;public-ip-address&gt;
</code></pre>
<p>    Replace &lt;IAM-user-name&gt; and &lt;public-ip-address&gt; with your own.</p>
<ul>
<li><p>Try the following command to check the initial connection with the internet</p>
<pre><code class="lang-bash">  ping google.com
</code></pre>
</li>
<li><p>Also, try to ping the public IPs of other servers i.e. <code>vpc2server</code> and <code>vpc3server</code></p>
<pre><code class="lang-bash">  ping &lt;public-ip-address&gt;
</code></pre>
<p>  Replace &lt;public-ip-address&gt; with copied public IP of the server and check connection is established or not.</p>
</li>
</ul>
<h3 id="heading-step-6-connect-to-another-server-of-the-same-region-using-the-virtual-server-that-we-are-connected-in">Step 6: Connect to another server of the same region using the virtual server that we are connected in</h3>
<ul>
<li><p>For window users only</p>
<ul>
<li><p>Open <code>myk.ppk</code> from the downloaded location and copy all contents</p>
</li>
<li><p>Using PuttyGen or another platform convert it to <code>pem</code> for example, let's choose any trusted online converter and copy the contents of <code>pem</code> file</p>
</li>
</ul>
</li>
<li><p>If you are a Linux user you already had <code>pem</code> file so open it and copy the contents</p>
</li>
<li><p>Now, go to the previously connected server and perform the following command</p>
<pre><code class="lang-bash">  nano new.pem
</code></pre>
<p>  And paste all that you copied using right-click, then Ctrl+O to save and Ctrl+X to exit.</p>
</li>
<li><p>Now. copy the public IP of <code>vpc2server</code> and perform the following command</p>
<pre><code class="lang-bash">  sudo su
  ssh -i <span class="hljs-string">"new.pem"</span> &lt;IAM-user-name&gt;@&lt;public-ip-address&gt;
</code></pre>
<ul>
<li><p>Replace &lt;IAM-user-name&gt; and &lt;public-ip-address&gt; and select yes if any prompt is asked.</p>
</li>
<li><p>Through <code>vpc1server</code> you connected with <code>vpc2server</code></p>
</li>
<li><p>Similarly, ping the public IPs of other servers i.e. <code>vpc1server</code> and <code>vpc3server</code></p>
<pre><code class="lang-bash">  ping &lt;public-ip-address&gt;
</code></pre>
<p>  Copy and Replace &lt;public-ip-address&gt; with copied public IP of the server and check connection is established or not.</p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-step-7-similarly-connect-to-the-server-of-the-other-region">Step 7: Similarly, Connect to the server of the other region</h3>
<ul>
<li><p>For window users only</p>
<ul>
<li><p>Open <code>mykey3.ppk</code> from the downloaded location and copy all contents</p>
</li>
<li><p>Using PuttyGen or another platform convert it to <code>pem</code> for example, let's choose any trusted online converter and copy the contents of <code>pem</code> file</p>
</li>
</ul>
</li>
<li><p>If you are a Linux user you already had <code>pem</code> file so open it and copy the contents</p>
</li>
<li><p>Now, go to the previously connected server and perform the following command</p>
<pre><code class="lang-bash">  nano new.pem
</code></pre>
<p>  And paste all that you copied using right-click, then Ctrl+O to save and Ctrl+X to exit.</p>
</li>
<li><p>Now. copy the public IP of <code>vpc2server</code> and perform the following command</p>
<pre><code class="lang-bash">  sudo su
  ssh -i <span class="hljs-string">"new.pem"</span> &lt;IAM-user-name&gt;@&lt;public-ip-address&gt;
</code></pre>
<p>  Replace &lt;IAM-user-name&gt; and &lt;public-ip-address&gt; and select yes if any prompt is asked.</p>
<ul>
<li><p>Through <code>vpc2server</code> you connected with <code>vpc3server</code> located in a different region</p>
</li>
<li><p>Similarly, ping the public IPs of other servers i.e. <code>vpc1server</code> and <code>vpc2server</code></p>
<pre><code class="lang-bash">  ping &lt;public-ip-address&gt;
</code></pre>
<p>  Copy and Replace &lt;public-ip-address&gt; with copied public IP of the server and check connection is established or not.</p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-which-shows-the-use-case-of-vpc-peering">Which shows the use case of VPC peering.</h3>
<p><strong><mark>Close all resources you created</mark></strong></p>
<h2 id="heading-thank-you-happy-learning">Thank you !!! Happy Learning!</h2>
]]></content:encoded></item><item><title><![CDATA[Let's connect VS Code with RDS for MySQL]]></title><description><![CDATA[What is Amazon Relational Database Service (RDS)?
Amazon Relational Database Service (Amazon RDS) is a web service that makes it easier to set up, operate, and scale a relational database in the AWS Cloud. It provides cost-efficient, resizable capaci...]]></description><link>https://blog.lokendrabhat.com.np/lets-connect-vs-code-with-rds-for-mysql</link><guid isPermaLink="true">https://blog.lokendrabhat.com.np/lets-connect-vs-code-with-rds-for-mysql</guid><category><![CDATA[amazon-rds]]></category><category><![CDATA[vscode extensions]]></category><dc:creator><![CDATA[Lokendra Bhat]]></dc:creator><pubDate>Tue, 13 Jun 2023 13:52:19 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1686664271301/deddf653-05b3-4b46-96b2-5ad18cb692e0.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-what-is-amazon-relational-database-service-rds">What is Amazon Relational Database Service (RDS)?</h3>
<p>Amazon Relational Database Service (Amazon RDS) is a web service that makes it easier to set up, operate, and scale a relational database in the AWS Cloud. It provides cost-efficient, resizable capacity for an industry-standard relational database and manages common database administration tasks.</p>
<h2 id="heading-lab-connect-vs-code-with-amazon-rds">LAB: Connect VS Code with Amazon RDS</h2>
<p>In this lab, we are going to create a basic database in RDS to understand how to establish the connection between the RDS database and VS Code. So that we can access the database created in RDS and use it from VS Code text editor.</p>
<h3 id="heading-step-1-create-a-database-in-rds">Step 1: Create a Database in RDS</h3>
<ul>
<li><p>Search RDS and Select it</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1686659853658/6b02c07a-b6f7-4dcd-88c7-ff8d241f93f8.jpeg" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong>Then Click on <mark>Create database </mark> and config as the information given:</strong></p>
<ul>
<li><p>Choose a database creation method: <code>Standard</code></p>
</li>
<li><p>Engine option: <code>MySQL</code></p>
</li>
<li><p>Templates: <code>Free tier</code></p>
</li>
<li><p>Settings:</p>
<ul>
<li><p>DB instance identifier: <code>demo-db</code></p>
</li>
<li><p>Credentials Settings &gt; Master Username: <code>admin</code></p>
</li>
<li><p>Credentials Settings &gt; Master password: <code>**********</code></p>
</li>
<li><p>Credentials Settings &gt; Confirm master password: <code>**********</code></p>
</li>
</ul>
</li>
<li><p>Storage:</p>
<ul>
<li><p>Storage type: <code>General Purpose SSD(gp2)</code></p>
</li>
<li><p>Storage autoscaling: <mark>you can uncheck </mark> <code>Enable storage autoscaling</code></p>
</li>
</ul>
</li>
<li><p>Connectivity:</p>
<ul>
<li><p>Compute resource: <code>Don’t connect to an EC2 compute resource</code></p>
</li>
<li><p>Virtual private cloud (VPC): <code>Default VPC</code></p>
<p>  { Note: If you don't have Default VPC and don't know how to create VPC you can learn from my <a target="_blank" href="https://blog.lokendrabhat1.com.np/amazon-virtual-private-cloud-vpc">Here and comment if any doubt</a>. }</p>
</li>
<li><p>Public access: <code>Yes</code></p>
</li>
<li><p>VPC security group (firewall): Leave <code>default</code></p>
</li>
<li><p>Availability Zone: <code>You can choose any</code></p>
</li>
</ul>
</li>
<li><p>Database authentication: Check <code>Password authentication</code></p>
</li>
<li><p>Monitoring: <code>Unchecked</code></p>
</li>
<li><p><strong>Additional configuration:</strong></p>
<ul>
<li><p>Initial database name: <code>demo</code></p>
</li>
<li><p>Backup: <mark>Uncheck </mark> <code>enable automated backups</code></p>
</li>
<li><p>Encryption: <mark>Uncheck </mark> <code>Enable encryption</code></p>
</li>
</ul>
</li>
</ul>
</li>
<li><p>Leave all Default and <strong><mark>Create database</mark></strong></p>
<ul>
<li><p>After sometime when <code>Status</code> of database <code>modifying</code> or <code>Available</code></p>
</li>
<li><p>click on <code>demo-bd</code> -&gt; Scroll down in <code>Connectivity &amp; Security</code></p>
</li>
<li><p>For future use Copy <code>Endpoint</code> marked as:</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1686662689316/c50ab6b2-9627-4284-8d33-ddf78aad8b8b.jpeg" alt class="image--center mx-auto" /></p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-step-2-update-vpc-default-security-group-as">Step 2: Update VPC Default Security group as:</h3>
<ul>
<li><p>Search VPC and Select it</p>
</li>
<li><p>Scroll the left-side-bar and select the <code>security groups</code></p>
</li>
<li><p>Click on the Security group ID which has the Security group name: <code>default</code></p>
</li>
<li><p>Click on <code>Edit inbound rules</code></p>
<ul>
<li><p>Click <code>Add rule</code></p>
<ul>
<li><p>Type: <code>MYSQL/Aurora</code></p>
</li>
<li><p>Source: <code>Anywhere-IPv4</code> i.e. <code>0.0.0.0/0</code> (- If you created a new security group add this rule as inbound as well )</p>
</li>
</ul>
</li>
<li><p><strong><mark>Save rules</mark></strong></p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-step-3-work-with-vs-code">Step 3: Work with VS Code</h3>
<ul>
<li><p>Install VS Code</p>
</li>
<li><p>Download following extensions</p>
<ul>
<li><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1686661707671/a09fc485-ba98-4de5-8baf-49b57f503ef3.jpeg" alt class="image--center mx-auto" /></p>
</li>
<li><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1686661695547/61ff90cd-a81a-47ec-8e05-f0778577767a.jpeg" alt class="image--center mx-auto" /></p>
</li>
<li><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1686661676946/8f1ebcc3-3280-45c7-8c35-2dca66bf9501.jpeg" alt class="image--center mx-auto" /></p>
</li>
</ul>
</li>
<li><p>Create any directory or folder on your computer</p>
</li>
<li><p>open the folder and right click</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1686662003298/687820b8-1fbe-4b3b-9dcb-c98ee0ac93f2.jpeg" alt class="image--center mx-auto" /></p>
</li>
<li><p>Click on Open in Terminal and type the following command to open that folder in VS Code directly</p>
<pre><code class="lang-bash">  code .
</code></pre>
</li>
<li><p>Click on <code>SQLTools</code> symbol</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1686662276861/f9313e79-94b8-41fb-84b6-7650d25b399a.jpeg" alt class="image--center mx-auto" /></p>
</li>
<li><p>Also, click on <code>Add New Connection</code></p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1686662398364/448afb64-254d-4e9b-a61a-084438820d75.jpeg" alt class="image--center mx-auto" /></p>
</li>
<li><p>Select <code>MySQL</code> and fill as:</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1686662998130/6e0d8547-66a8-475b-8bd7-329aa70c0a39.jpeg" alt class="image--center mx-auto" /></p>
</li>
<li><p>Click on <code>TEST CONNECTION</code> enter the password you set above while creating RDS</p>
</li>
<li><p>You should get <code>Successfully connected!</code> message</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1686663103689/dd5635c7-8c69-4775-88a2-0f66cfe673a2.jpeg" alt class="image--center mx-auto" /></p>
</li>
<li><p>Now Click on <strong><mark>SAVE CONNECTION </mark></strong> -&gt; <strong><mark>CONNECT NOW</mark></strong></p>
</li>
</ul>
<p><strong>CONGRATULATIONS YOU HAVE SUCCESSFULLY CONNECTED WITH RDS</strong></p>
<p>Now you can do any SQL query and run on VS Code...</p>
<h1 id="heading-thank-you-for-learning">Thank you for LEARNING !!!</h1>
]]></content:encoded></item><item><title><![CDATA[AWS VPC Peering]]></title><description><![CDATA[What is actually VPC peering?
A virtual private cloud (VPC) is a virtual network dedicated to your AWS account. It is logically isolated from other virtual networks in the AWS Cloud. You can launch AWS resources, such as Amazon EC2 instances, into yo...]]></description><link>https://blog.lokendrabhat.com.np/aws-vpc-peering</link><guid isPermaLink="true">https://blog.lokendrabhat.com.np/aws-vpc-peering</guid><category><![CDATA[vpc]]></category><category><![CDATA[vpc peering]]></category><category><![CDATA[AWS]]></category><dc:creator><![CDATA[Lokendra Bhat]]></dc:creator><pubDate>Sun, 11 Jun 2023 14:29:54 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1686493735533/5896d46a-fc2d-4557-88d1-d5c65e20d505.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-what-is-actually-vpc-peering">What is actually VPC peering?</h3>
<p>A <em>virtual private cloud</em> (VPC) is a virtual network dedicated to your AWS account. It is logically isolated from other virtual networks in the AWS Cloud. You can launch AWS resources, such as Amazon EC2 instances, into your VPC.</p>
<p>A VPC peering connection is a networking connection between two VPCs that enables you to route traffic between them using private IPv4 addresses or IPv6 addresses. Instances in either VPC can communicate as if they are within the same network. You can create a VPC peering connection between your VPCs or a VPC in another AWS account. The VPCs can be in different Regions (also known as an inter-Region VPC peering connection).</p>
<h3 id="heading-pricing-for-a-vpc-peering-connection"><strong>Pricing for a VPC peering connection</strong></h3>
<p>There is no charge to create a VPC peering connection. All data transfer over a VPC Peering connection within an Availability Zone (AZ) is free. Charges apply for data transfer over VPC Peering connections that cross Availability Zones and Regions.</p>
<h2 id="heading-lab-how-to-create-vpc-peering">LAB: How to create VPC peering?</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1686486608564/490cc68e-e79d-43c2-96ad-439fb8b9e4b4.png" alt class="image--center mx-auto" /></p>
<p>Note: In this lab session we are going to create two different instances and try to connect the private IP of one instance by using another instance.</p>
<h3 id="heading-step-1-create-a-first-vpc">Step 1: Create a First VPC</h3>
<ol>
<li><p><strong>Goto</strong> <code>Your VPCs</code> <strong>and Create vpc1:</strong></p>
<ul>
<li><p>Resources to create <code>VPC only</code></p>
</li>
<li><p>Name tag - optional eg. <code>vpc1</code></p>
</li>
<li><p>IPv4 CIDR eg. <code>10.0.0.0/16</code></p>
<p>  <strong><mark>Create VPC </mark></strong> with all other default</p>
</li>
</ul>
</li>
<li><p><strong>Goto</strong> <code>Subnets</code> <strong>and create subnet for</strong> <code>vpc1</code> <strong>as:</strong></p>
<ul>
<li><p>VPC ID select <code>vpc1</code></p>
</li>
<li><p>Scroll down to Subnet settings</p>
<ul>
<li><p>Subnet name <code>vpc1subnet</code></p>
</li>
<li><p>Availability Zone anyone your choice eg. <code>us-east-1a</code></p>
</li>
<li><p>IPv4 CIDR block: <code>10.0.0.0/24</code></p>
<p>  and <strong><mark>Create subnet</mark></strong></p>
</li>
</ul>
</li>
</ul>
</li>
<li><p>Goto <code>Internet gateways</code> and Create internet gateway as:</p>
<ul>
<li><p>In Internet gateway setting</p>
<ul>
<li><p>Name tag: <code>IGvpc1</code></p>
</li>
<li><p><strong><mark>Create internet gateway</mark></strong></p>
</li>
</ul>
</li>
<li><p>Click on the popup <strong>Attach to VPC</strong></p>
<ul>
<li><p>Available VPCs -&gt; select a VPC : <code>vpc1</code></p>
<p>  <strong><mark>Attach internet gateway</mark></strong></p>
</li>
</ul>
</li>
</ul>
</li>
<li><p>Goto <code>Route tables</code> and create a route table for <code>vpc1</code></p>
<ul>
<li><p>Route table settings</p>
<ul>
<li><p>Name: <code>route_vpc1</code></p>
</li>
<li><p>VPC: Select <code>vpc1</code></p>
<p>  <strong><mark>Create route table</mark></strong></p>
</li>
</ul>
</li>
</ul>
</li>
</ol>
<h3 id="heading-step-2-similarly-create-a-second-vpc">Step 2: Similarly, Create a Second VPC</h3>
<ol>
<li><p><strong>Goto</strong> <code>Your VPCs</code> <strong>and Create vpc2:</strong></p>
<ul>
<li><p>Resources to create <code>VPC only</code></p>
</li>
<li><p>Name tag - optional eg. <code>vpc2</code></p>
</li>
<li><p>IPv4 CIDR eg. <code>194.0.0.0/16</code></p>
<p>  <strong><mark>Create VPC </mark></strong> with all other default</p>
</li>
</ul>
</li>
<li><p><strong>Goto</strong> <code>Subnets</code> <strong>and create subnet for</strong> <code>vpc2</code> <strong>as:</strong></p>
<ul>
<li><p>VPC ID select <code>vpc2</code></p>
</li>
<li><p>Scroll down to Subnet settings</p>
<ul>
<li><p>Subnet name <code>vpc2subnet</code></p>
</li>
<li><p>Availability Zone anyone your choice eg. <code>us-east-1b</code></p>
</li>
<li><p>IPv4 CIDR block: <code>194.0.0.0/24</code></p>
<p>  and <strong><mark>Create subnet</mark></strong></p>
</li>
</ul>
</li>
</ul>
</li>
<li><p>Goto <code>Internet gateways</code> and Create internet gateway as:</p>
<ul>
<li><p>In Internet gateway setting</p>
<ul>
<li><p>Name tag: <code>IGvpc2</code></p>
</li>
<li><p><strong><mark>Create internet gateway</mark></strong></p>
</li>
</ul>
</li>
<li><p>Click on the popup <strong>Attach to VPC</strong></p>
<ul>
<li><p>Available VPCs -&gt; Select a VPC : <code>vpc2</code></p>
<p>  <strong><mark>Attach internet gateway</mark></strong></p>
</li>
</ul>
</li>
</ul>
</li>
<li><p>Goto <code>Route tables</code> and create a route table for <code>vpc2</code></p>
<ul>
<li><p>Route table settings</p>
<ul>
<li><p>Name: <code>route_vpc2</code></p>
</li>
<li><p>VPC: Select <code>vpc2</code></p>
<p>  <strong><mark>Create route table</mark></strong></p>
</li>
</ul>
</li>
</ul>
</li>
</ol>
<h3 id="heading-step-3-now-create-a-peering-connection">Step 3: Now, Create a peering connection:</h3>
<ul>
<li><p>Goto <code>Peering connections</code> by scrolling down on the left side of the bar</p>
</li>
<li><p>Click on <mark>Create peering connection</mark></p>
</li>
<li><p>Peering connection settings</p>
<ul>
<li><p>Name: <code>peerVPC</code></p>
</li>
<li><p>VPC ID (Requester): Select <code>vpc1</code></p>
</li>
<li><p>VPC ID (Accepter): Select <code>vpc2</code></p>
<p>  <mark>Create peering connection</mark></p>
</li>
</ul>
</li>
<li><p>Select <code>peerVPC</code> -&gt; <code>Actions</code> -&gt; <code>Accept request</code></p>
</li>
</ul>
<h3 id="heading-step-4-last-thing-to-do-modify-a-route-table">Step 4: Last thing to do Modify a route table:</h3>
<ul>
<li><p>Goto <code>Route tables</code></p>
</li>
<li><p>Select <code>route_vpc1</code></p>
<ul>
<li><p>Click on <code>Subnet associations</code> -&gt; <code>Edit subnet associations</code></p>
<ul>
<li>Available subnets: Select <code>vpc1subnet</code> and <mark>Save associations</mark></li>
</ul>
</li>
<li><p>Click on <code>Routes</code> -&gt; <code>Edit routes</code> -&gt; <code>Add route</code></p>
<p>  Destination: <code>0.0.0.0/0</code> Targe: <code>Internet Gateway</code> -&gt; <code>(IGvpc1)</code></p>
<p>  Destination: <code>194.0.0.0/16</code> Targe: <code>Peering Connection</code> -&gt; <code>(peerVPC)</code></p>
</li>
</ul>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1686490799813/829d396d-afb3-4164-9268-fdc0bdfb9f91.jpeg" alt class="image--center mx-auto" /></p>
<ul>
<li><p>Similarly, Select <code>route_vpc2</code></p>
<ul>
<li><p>Click on <code>Subnet associations</code> -&gt; <code>Edit subnet associations</code></p>
<ul>
<li>Available subnets: Select <code>vpc2subnet</code> and <mark>Save associations</mark></li>
</ul>
</li>
<li><p>Click on <code>Routes</code> -&gt; <code>Edit routes</code> -&gt; <code>Add route</code></p>
<p>  Destination: <code>0.0.0.0/0</code> Targe: <code>Internet Gateway</code> -&gt; <code>(IGvpc2)</code></p>
<p>  Destination: <code>10.0.0.0/16</code> Targe: <code>Peering Connection</code> -&gt; <code>(peerVPC)</code></p>
</li>
</ul>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1686491046077/dddf949b-7edb-40dc-99e6-83a9b0850518.jpeg" alt class="image--center mx-auto" /></p>
<h3 id="heading-step-4-now-smile-all-vpc-work-was-done-next-goto-ec2-andgt-instances">Step 4: Now, Smile all VPC work was done. Next goto EC2 -&gt; instances</h3>
<ol>
<li><p><strong>For First Instance</strong></p>
<ul>
<li><p>Launch instances</p>
</li>
<li><p>Name: <code>server1</code></p>
</li>
<li><p>select the existing key or create new</p>
</li>
<li><p>Network settings -&gt; <code>Edit</code></p>
<ul>
<li><p>VPC: Select <code>vpc1</code></p>
</li>
<li><p>Subnet: <code>vpc1subnet</code></p>
</li>
<li><p>Auto-assign public IP: <code>enable</code></p>
</li>
<li><p>Leave Create a security group checked</p>
</li>
<li><p>Leave all default and <strong><mark>Launch instance</mark></strong></p>
</li>
</ul>
</li>
</ul>
</li>
<li><p><strong>For Second Instance</strong></p>
<ul>
<li><p>Launch instances</p>
</li>
<li><p>Name: <code>server2</code></p>
</li>
<li><p>select the existing key or create new</p>
</li>
<li><p>Network settings -&gt; <code>Edit</code></p>
<ul>
<li><p>VPC: Select <code>vpc2</code></p>
</li>
<li><p>Subnet: <code>vpc2subnet</code></p>
</li>
<li><p>Auto-assign public IP: <code>desable</code></p>
</li>
<li><p>Leave Create a security group checked</p>
</li>
<li><p><code>Add security group rule</code></p>
<ul>
<li><p>Type: <code>All traffic</code></p>
</li>
<li><p>Source type: <code>Anywhere</code></p>
<p>  [ Note: It is not good practice to set the type <code>All traffic</code> just for basic understanding ]</p>
</li>
</ul>
</li>
<li><p>Leave all default and <strong><mark>Launch instance</mark></strong></p>
</li>
</ul>
</li>
</ul>
</li>
</ol>
<h3 id="heading-step-4-connect-the-ec2-instance">Step 4: Connect the EC2 instance</h3>
<ul>
<li><p>After the Status check <code>2/2 checks passed</code></p>
</li>
<li><p>Select the EC2 instance with private IP i.e. <code>server2</code> and copy private IP</p>
</li>
<li><p>Then, Select the EC2 instance with public IP i.e. <code>server1</code></p>
</li>
<li><p>And Click on <code>Connect</code> at the top, again <mark>Connect</mark></p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1686492508054/ebb26b99-1891-4239-a869-b1028535a93c.jpeg" alt class="image--center mx-auto" /></p>
<ul>
<li>Now, you reached this window:</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1686492594539/e96ec54d-f131-49ae-a708-c4a41ea5bfde.jpeg" alt class="image--center mx-auto" /></p>
<ul>
<li><p>Here, perform the following commands:</p>
<pre><code class="lang-bash">  sudo su
</code></pre>
<pre><code class="lang-bash">  ping &lt;private-ip-you-copied&gt;
</code></pre>
<ul>
<li>You get the following output <code>CTRL+C to exit</code></li>
</ul>
</li>
</ul>
<p>    <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1686492999197/1fc8baed-29c7-46fe-82fa-dedd502a3c4e.jpeg" alt class="image--center mx-auto" /></p>
<h3 id="heading-dont-forget-to-terminate-all-the-services-you-started">Don't forget to terminate all the services you started...</h3>
<h1 id="heading-thanks-for-your-time"><strong><em>Thanks for your time</em></strong></h1>
]]></content:encoded></item><item><title><![CDATA[Amazon S3 Storage Classes]]></title><description><![CDATA[S3 Standard

S3 - Intelligent Tiering

S3 Standard IA(Infrequent Access)

S3 One Zone - IA

S3 Glacier Instant Retrieval

S3 Glacier Flexible Retrieval (Formerly S3 Glacier)

S3 Glacier Deep Archive



S3 Standard

Costly than others

Use only when y...]]></description><link>https://blog.lokendrabhat.com.np/amazon-s3-storage-classes</link><guid isPermaLink="true">https://blog.lokendrabhat.com.np/amazon-s3-storage-classes</guid><category><![CDATA[Amazon S3]]></category><dc:creator><![CDATA[Lokendra Bhat]]></dc:creator><pubDate>Fri, 02 Jun 2023 16:35:11 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1685723640056/013e8857-9f3e-4fd3-9638-acbdfc99f0d1.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<ol>
<li><p><strong>S3 Standard</strong></p>
</li>
<li><p><strong>S3 - Intelligent Tiering</strong></p>
</li>
<li><p><strong>S3 Standard IA(Infrequent Access)</strong></p>
</li>
<li><p><strong>S3 One Zone - IA</strong></p>
</li>
<li><p><strong>S3 Glacier Instant Retrieval</strong></p>
</li>
<li><p><strong>S3 Glacier Flexible Retrieval (Formerly S3 Glacier)</strong></p>
</li>
<li><p><strong>S3 Glacier Deep Archive</strong></p>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1685722615919/502817fc-a9e1-4cbd-ac68-79c165ec3d04.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-s3-standard">S3 Standard</h3>
<ul>
<li><p>Costly than others</p>
</li>
<li><p>Use only when you have very critical data which was not afforded to lose</p>
</li>
<li><p>Low latency, Fast Retrieval, and high throughput performance</p>
</li>
<li><p>Replication object across all availability zone of any Region</p>
</li>
<li><p>Fast Retrieval</p>
</li>
<li><p>Highly Available: Designed for 99.99% availability over a given year</p>
</li>
<li><p>Supports SSL for data in transit and encryption of data at rest</p>
</li>
<li><p>S3 Lifecycle management for automatic migration of objects to other S3 Storage Classes  </p>
</li>
</ul>
<h3 id="heading-s3-intelligent-tiering">S3 - Intelligent Tiering</h3>
<ul>
<li><p>Designed to optimize costs by automatically moving data to the most cost-effective access tier, without performance impact or operational overhead.</p>
</li>
<li><p>Frequent, Infrequent, and Archive Instant Access tiers have the same low-latency and high-throughput performance as S3 Standard</p>
</li>
<li><p>The Infrequent Access tier saves up to 40% on storage costs</p>
</li>
<li><p>The Archive Instant Access tier saves up to 68% on storage costs</p>
</li>
<li><p>Opt-in asynchronous archive capabilities for objects that become rarely accessed</p>
</li>
<li><p>The deep Archive Access tier has the same performance as Glacier Deep Archive and saves up to 95% for rarely accessed objects</p>
</li>
<li><p>Highly availability: 99.9% availability over a given year</p>
</li>
<li><p>Small monthly monitoring and auto-tiering charge</p>
</li>
<li><p>No operational overhead, no lifecycle charges, no retrieval charges, and no minimum storage duration</p>
</li>
<li><p>Objects smaller than 128KB can be stored in S3 Intelligent Tiering but will always be charged at the Frequent Access tier rates, and are not charged the monitoring and automation charge.</p>
</li>
<li><p>So for more cost optimization need an object size &gt;= 128 KB</p>
</li>
</ul>
<h3 id="heading-s3-standard-ia">S3 - Standard IA</h3>
<ul>
<li><p>Same low latency and high throughput performance of S3 Standard</p>
</li>
<li><p>Replication across all availability zone of any Region</p>
</li>
<li><p>Resilient against events that impact an entire Availability Zone</p>
</li>
<li><p>Data is resilient in the event of one entire Availability Zone destruction</p>
</li>
<li><p>Highly Available: 99.9% availability over a given year</p>
</li>
<li><p>Supports SSL for data in transit and encryption of data at rest</p>
</li>
<li><p>S3 Lifecycle management for automatic migration of objects to other S3 Storage Classes</p>
</li>
<li><p>Fast Retrieval</p>
</li>
<li><p>Less costly compared to standard</p>
</li>
<li><p>The minimum Size of the file is 128KB to use the Standard IA storage class</p>
</li>
<li><p>An object should be there for at least 30 days in Standard to move to Standard IA</p>
</li>
</ul>
<h3 id="heading-s3-one-zone-ia">S3 One Zone - IA</h3>
<ul>
<li><p>No replication: objects in a only single Availability Zone</p>
</li>
<li><p>Same low latency and high throughput performance of S3 Standard</p>
</li>
<li><p>Less durable</p>
</li>
<li><p>Less available: 99.5% availability over a given year</p>
</li>
<li><p>Lower cost</p>
</li>
<li><p>Less critical data are stored in this class</p>
</li>
<li><p>Data should be there 30 days in Standard</p>
</li>
<li><p>Supports SSL for data in transit and encryption of data at rest</p>
</li>
<li><p>S3 Lifecycle management for automatic migration of objects to other S3 Storage Classes</p>
</li>
</ul>
<h3 id="heading-s3-glacier-instant-retrieval">S3 Glacier <strong>Instant Retrieval</strong></h3>
<ul>
<li><p>Data retrieval in milliseconds with the same performance as S3 Standard</p>
</li>
<li><p>Replication of objects across multiple Availability Zones</p>
</li>
<li><p>Data is resilient in the event of the destruction of one entire Availability Zone</p>
</li>
<li><p>Designed for 99.9% data availability in a given year</p>
</li>
<li><p>128 KB minimum object size and Data should be there 90 days in other classes to move in Glacier</p>
</li>
<li><p>S3 PUT API for direct uploads to S3 Glacier Instant Retrieval, and S3 Lifecycle management for automatic migration of objects</p>
</li>
<li><p>It is a low-cost storage class</p>
</li>
<li><p>Data Archiving</p>
</li>
<li><p>Retrieval times are configurable from minutes to hours</p>
</li>
<li><p>Infrequently access</p>
</li>
</ul>
<h3 id="heading-s3-glacier-flexible-retrieval"><strong>S3 Glacier Flexible Retrieval</strong></h3>
<ul>
<li><p>Low-cost storage, up to 10% lower cost (than S3 Glacier Instant Retrieval)</p>
</li>
<li><p>For archive data that is accessed 1-2 times per year and is retrieved asynchronously</p>
</li>
<li><p>Replication of objects across multiple Availability Zones</p>
</li>
<li><p>Data is resilient in the event of one entire Availability Zone destruction</p>
</li>
<li><p>Supports SSL for data in transit and encryption of data at rest</p>
</li>
<li><p>Ideal for backup and disaster recovery use cases when large sets of data occasionally need to be retrieved in minutes, without concern for costs</p>
</li>
<li><p>Configurable retrieval times, from minutes to hours, with free bulk retrievals</p>
</li>
<li><p>S3 PUT API for direct uploads to S3 Glacier Flexible Retrieval, and S3 Lifecycle management for automatic migration of objects</p>
</li>
</ul>
<h3 id="heading-s3-glacier-deep-archive">S3 Glacier Deep Archive</h3>
<ul>
<li><p>Cheapest deep archival storage class designed for long-term retention of data that will be retained for 7-10 years</p>
</li>
<li><p>Retrieval time within 12 hours</p>
</li>
<li><p>Infrequental access</p>
</li>
<li><p>Replication of objects across multiple Availability Zones</p>
</li>
<li><p>Ideal alternative to magnetic tape libraries</p>
</li>
<li><p>S3 PUT API for direct uploads to S3 Glacier Deep Archive, and S3 Lifecycle management for automatic migration of objects</p>
</li>
</ul>
<h2 id="heading-s3-on-outposts"><strong>S3 on Outposts</strong></h2>
<p><strong>Key Features:</strong></p>
<ul>
<li><p>S3 Object compatibility and bucket management through the S3 SDK</p>
</li>
<li><p>Designed to durably and redundantly store data on your Outposts</p>
</li>
<li><p>Encryption using SSE-S3 and SSE-C</p>
</li>
<li><p>Authentication and authorization using IAM, and S3 Access Points</p>
</li>
<li><p>Transfer data to AWS Regions using AWS DataSync</p>
</li>
<li><p>S3 Lifecycle expiration actions</p>
</li>
</ul>
<h2 id="heading-key-points">KEY Points</h2>
<ul>
<li><p>All classes are highly durable i.e. 99.999999999%</p>
</li>
<li><p>A single bucket can contain objects stored across S3 Standard, S3 Intelligent-Tiering, S3 Standard-IA, and S3 One Zone-IA</p>
</li>
<li><p>Because S3 One Zone-IA stores data in a single AWS Availability Zone, data stored in this storage class will be lost in the event of Availability Zone destruction.</p>
</li>
<li><p><strong>S3 Intelligent - Tiering</strong>* - Automatic cost savings for data with unknown or changing access patterns</p>
</li>
<li><p><strong>S3 Standard - Infrequent Access</strong> - For long-lived but infrequently accessed data that needs millisecond access</p>
</li>
<li><p><strong>S3 Glacier Instant Retrieval</strong>* - For long-lived archive data accessed once a quarter with instant retrieval in milliseconds</p>
</li>
<li><p><strong>S3 Glacier Flexible Retrieval (Formerly S3 Glacier)</strong>**- For long-term backups and archives with retrieval option from 1 minute to 12 hours</p>
</li>
<li><p><strong>S3 Glacier Deep Archive</strong>*** - For long-term data archiving that is accessed once or twice a year and can be restored within 12 hours</p>
</li>
</ul>
<h2 id="heading-performance-across-the-s3-storage-classes"><strong>Performance across the S3 Storage Classes</strong></h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1685722598748/22704605-a2cb-4062-8210-50d687070340.webp" alt class="image--center mx-auto" /></p>
]]></content:encoded></item><item><title><![CDATA[Connect S3 with EC2]]></title><description><![CDATA[Create S3 bucket with the following information:

Bucket name: must be globally unique

AWS Region: your choice

Object Ownership: ACLs enabled

uncheck Block all public access

Check I acknowledge that the current settings might result in this bucke...]]></description><link>https://blog.lokendrabhat.com.np/connect-s3-with-ec2</link><guid isPermaLink="true">https://blog.lokendrabhat.com.np/connect-s3-with-ec2</guid><category><![CDATA[ec2]]></category><category><![CDATA[S3]]></category><category><![CDATA[AWS]]></category><dc:creator><![CDATA[Lokendra Bhat]]></dc:creator><pubDate>Thu, 01 Jun 2023 18:22:55 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1685643682740/6b56679c-511e-4930-96b8-f93dfc51b9e6.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-create-s3-bucket-with-the-following-information">Create S3 bucket with the following information:</h3>
<ul>
<li><p>Bucket name: <code>must be globally unique</code></p>
</li>
<li><p>AWS Region: <code>your choice</code></p>
</li>
<li><p>Object Ownership: <code>ACLs enabled</code></p>
</li>
<li><p>uncheck <code>Block all public access</code></p>
</li>
<li><p>Check <code>I acknowledge that the current settings might result in this bucket and the objects within becoming public.</code></p>
</li>
<li><p><strong>Bucket Versioning:</strong> <code>enable (preferred) or disable as your requirement</code></p>
</li>
<li><p><code>Create bucket</code></p>
</li>
<li><p>Click on <code>bucket name</code> and upload the object you want for example any <code>image</code></p>
</li>
<li><p>While uploading scroll down and open <code>&gt; Permission</code></p>
<p>  Predefined ACLs: <code>Grant public-read access</code></p>
<p>  <code>I understand the risk of granting public-read access to the specified objects.</code></p>
<p>  [ NOTE: if you forget to give ACL public access <code>check object</code> goto <code>^Action</code> and scroll down and <code>click make public using ACL</code> -&gt; <code>Make public</code></p>
</li>
<li><p>open bucket -&gt; Check the object and <code>Copy URL</code></p>
</li>
</ul>
<h3 id="heading-create-ec2-instance-with-the-following-information">Create EC2 instance with the following information:</h3>
<ul>
<li><p>Name: <code>my-server</code></p>
</li>
<li><p>Key pair: <code>create new key pair</code></p>
<ul>
<li><p>Key pair name: <code>mykeypair</code></p>
</li>
<li><p>Private key file format: <code>.ppk For PuTTY user</code> <code>.pem For use with OpenSSH</code></p>
</li>
</ul>
</li>
<li><p><code>Allow SSH traffic</code><br />  <code>Allow HTTP traffic from the internet</code> (<em>note you may also enable</em> <code>https</code> )</p>
</li>
<li><p><code>Launch instance</code></p>
</li>
</ul>
<h3 id="heading-run-virtual-machine">Run virtual machine</h3>
<ul>
<li><p>Connect EC2 using the key you downloaded either by putty or ssh</p>
</li>
<li><p>After connected as <code>ec2-use</code></p>
<pre><code class="lang-bash">  ]$ <span class="hljs-built_in">pwd</span>
  /home/ec2-user
</code></pre>
</li>
</ul>
<p>Install Apache server</p>
<pre><code class="lang-bash">]$ sudo yum install httpd -y
</code></pre>
<pre><code class="lang-bash">]$ sudo systemctl status
● ip-172-31-84-163.ec2.internal
    State: running
    Units: 281 loaded (incl. loaded aliases)
     Jobs: 0 queued
   Failed: 0 units
    Since: Thu 2023-06-01 17:42:25 UTC; 16min ago
  systemd: 252.4-1161.amzn2023.0.4
</code></pre>
<pre><code class="lang-bash">]$ <span class="hljs-built_in">cd</span> /var/www/html
]$ <span class="hljs-built_in">pwd</span>

]$ sudo nano index.html
</code></pre>
<ul>
<li>Paste the copied URL of the object as:</li>
</ul>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://my-uniue-bucket-1.s3.amazonaws.com/Shared_Responsibility_Model_V2.59d1eccec334b366627e9295b304202faf7b899b.jpg"</span>/&gt;</span>
</code></pre>
<pre><code class="lang-bash">]$ sudo systemctl start httpd
]$ sudo systemctl status httpd
● httpd.service - The Apache HTTP Server
     Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; preset: disabled)
     Active: active (running) since Thu 2023-06-01 18:08:55 UTC; 17s ago
       Docs: man:httpd.service(8)
   Main PID: 26020 (httpd)
</code></pre>
<h3 id="heading-now-you-can-access-your-s3-object-using-the-public-ip-of-ec2-instance">Now you can access your S3 object using the public IP of EC2 instance</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1685643626252/7f307b53-4a3e-466f-99d8-6abf04eb4b25.jpeg" alt class="image--center mx-auto" /></p>
<h1 id="heading-thank-you-for-your-time">....../ THANK YOU FOR YOUR TIME \.....</h1>
]]></content:encoded></item><item><title><![CDATA[Amazon Virtual Private Cloud (VPC)]]></title><description><![CDATA[Points to be noted:

A  Virtual Private Gateway (VPC) is like a data center but in the cloud. Its logically isolated from other virtual networks from which you can spin up and launch your AWS resources within minutes.

Private Internet Protocol (IP) ...]]></description><link>https://blog.lokendrabhat.com.np/amazon-virtual-private-cloud-vpc</link><guid isPermaLink="true">https://blog.lokendrabhat.com.np/amazon-virtual-private-cloud-vpc</guid><category><![CDATA[AWS]]></category><category><![CDATA[Cloud]]></category><dc:creator><![CDATA[Lokendra Bhat]]></dc:creator><pubDate>Wed, 17 May 2023 17:43:34 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1684345230018/d57ce0d5-67e5-4cfc-9447-0acbeb98b1e7.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-points-to-be-noted">Points to be noted:</h3>
<ul>
<li><p><mark>A </mark> <strong><mark>Virtual Private Gateway (VPC)</mark></strong> is like a data center but in the cloud. Its logically isolated from other virtual networks from which you can spin up and launch your AWS resources within minutes.</p>
</li>
<li><p><strong><mark>Private Internet Protocol (IP)</mark></strong> addresses are how resources within the VPC communicate with each other. An instance needs a public IP address for it to communicate outside the VPC. The VPC will need networking resources such as an Internet Gateway (IGW) and a route table in order for the instance to reach the Internet.</p>
</li>
<li><p><strong><mark>An Internet Gateway (IGW)</mark></strong> is what makes it possible for the VPC to have Internet connectivity. It has two jobs: perform network address translation (NAT) and be the target to route traffic to the internet for the VPC. An IGW's route on a route table is always 0.0.0.0/0.</p>
</li>
<li><p><strong><mark>A subnet</mark></strong> is a range of IP addresses within your VPC.</p>
</li>
<li><p><strong><mark>A route table</mark></strong> contains routes for your subnet and directs traffic using the rules defined within the route table. You associate the route table to a subnet. If an IGW was on a route table, the destination would be 0.0.0.0/0 and the target would be IGW.</p>
</li>
<li><p><strong><mark>Security groups and Network Access Control Lists (NACLs)</mark></strong> work as the firewall within your VPC. Security groups work at the instance level and are stateful, which means they block everything by default. NACLs work at the subnet level and are stateless, which means they do not block everything by default.</p>
</li>
</ul>
<h2 id="heading-configuring-amazon-vpc-using-the-aws-management-console"><strong><em>Configuring</em></strong> Amazon VPC <strong><em>using the AWS Management console:</em></strong></h2>
<h3 id="heading-step-1-open-the-aws-account-search-and-click-vpc">Step 1: Open the AWS account, search, and click VPC</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684334335420/4ce79523-9385-4ef8-b647-ba81a186e57c.png" alt class="image--center mx-auto" /></p>
<p>click again on VPC</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684335171156/afb48955-f2b4-4be2-8fcb-d5e06f7d9376.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684335315789/50681d08-3b0e-4769-a65f-eb22df2ec573.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-step-2-click-on-vpc-only-give-the-name-of-your-choice-and-change-the-required-ipv4-cidr-as-needed-then-leave-all-other-things-to-default-scroll-down-and-click-create-vpc">Step 2: Click on VPC only, give the name of your choice, and change the required IPv4 CIDR as needed, then leave all other things to default, scroll down, and click <mark>Create VPC</mark>:</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684335434920/4d303c91-0d1e-4d2e-90d0-08e4ca31c093.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684335805522/00a6af8f-08aa-4ac9-8049-080f0538c6fc.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-step-3-after-the-above-interface-click-on-subnets-as-shown-and-again-click-on-create-subnet">Step 3: After the above interface click on Subnets as shown and again click on <mark>Create subnet</mark></h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684335935527/b3384c7b-6416-4cb0-be7e-cdabec5ff4f0.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-step-4-select-the-vpc-that-we-created-above">Step 4: Select the VPC that we created above</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684336074505/c9c692f4-9f57-4fc9-8e92-78365d034527.png" alt class="image--center mx-auto" /></p>
<p>Scroll down and give the Subnet name: <mark>private subnet</mark> or anything you like which going to be our private subnet, also select any availability zone of that region and specify the IPv4 CIDR block (eg. 10.0.0.0/24)according to your needs.</p>
<p>Also, repeat for a public subnet with a Subnet name: <mark>public subnet</mark> or anything you like which going to be our public subnet. Also select any availability zone of that region and specify the IPv4 CIDR block (eg. 10.0.1.0/24)according to your needs.</p>
<h3 id="heading-step-5-after-creating-two-subnets-we-have-to-create-two-route-tables-so-click-on-route-tables-and-then-create-route-table">Step 5: After creating two subnets we have to create two route tables so, click on Route tables and then <mark>Create route table</mark></h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684337211069/08840f95-2c18-492a-b1b4-203d11fa5bcf.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-step-6-give-any-name-you-like-and-select-vpc-which-we-created-above-and-then-create-route-table">Step 6: Give any name you like and select VPC which we created above and then <mark>Create route table</mark></h3>
<p><mark>For simplicity give names public_route_table and private_route_table and create two route tables.</mark></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684337488527/061a3ed4-87b7-4370-ac78-3bba3e6ec24e.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-step-7-now-click-on-internet-gateways-and-create-internet-gateway-as">Step 7: Now click on Internet gateways and Create Internet gateway as:</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684339189980/68b4950e-d88a-4739-8314-1140edb28b5a.png" alt class="image--center mx-auto" /></p>
<p>specify the gateway name as you like and click on <mark>Create internet gateway</mark></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684339246848/b595b0e5-9796-471b-b11b-56e0648dcb39.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-step-8-then-click-on-attach-to-vpc-and-attach-that-you-created-above-as">Step 8: Then click on Attach to VPC and attach that you created above as:</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684339315880/72603d99-5bc3-40fd-9505-8dda551ed799.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684339359053/2e32b533-2dc2-4188-9d84-8bd87aef6043.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-step-9-also-we-have-to-create-nat-as">Step 9: Also we have to create NAT as:</h3>
<ol>
<li>select NAT gateways and create NAT gateway</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684340733724/ea30d069-24f3-49ab-90e9-58a60699099d.png" alt class="image--center mx-auto" /></p>
<ol>
<li><p>Give a name eg. my-NAT and select a subnet that needs to be public.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684340840866/86f19034-845c-4527-9d80-99c7dc70843c.png" alt class="image--center mx-auto" /></p>
<ol>
<li>Then click on Allocate Elastic IP and Create NAT gateway</li>
</ol>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684340985307/eff70ca0-e42a-4025-9bef-88ae0fbe7489.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-step-10-add-route-to-route-table-and-associate-subnet-to-the-route-table">Step 10:  <strong>Add route to route table and associate subnet to the route table</strong></h3>
<ol>
<li><p>Goto route tables and select Route table ID of public_route_table</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684341218834/85659458-f6f3-4f45-8623-c6370c219ca7.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Click on Routes -&gt; Edit routes</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684341273791/4686d2d1-6c85-4ca7-9796-6108842ec04e.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Click on [Add route] -&gt; select 0.0.0.0/0 -&gt; Click in the <strong>Target</strong> section and select <strong>Internet Gateway</strong> that we created since you are targeting any traffic that needs to go to the internet to the IGW.</p>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684341362281/27e18024-4df4-4e21-8ff8-43f79b83d11b.png" alt class="image--center mx-auto" /></p>
<ol>
<li><p>Save changes -&gt; click on Subnet associations -&gt; Edit subnet associations</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684341540214/2072c283-0191-4d5b-9976-dbeb7567551e.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>select the public subnet for the public route table and <mark>save associations</mark></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684341717510/cb77c131-acfe-4fef-9401-047bc225d310.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Go back and select Route table ID of private_route_table</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684341901526/b52fac66-bb8c-436e-8136-e1df6e9bc082.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Routes -&gt; Edit routes</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684341981069/3fc0d364-c825-4099-b24d-36e462aaed5d.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Click on Add route -&gt; select 0.0.0.0/0 -&gt; select NAT Gateway -&gt; Save changes</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684342135450/86e46014-058c-43bf-8be0-8c49b0144dd9.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Goto Edit subnet associations and select private subnet for private route table -&gt; save associations.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684342239003/d0f8be91-2ef3-4b08-99b1-b156982ad428.png" alt class="image--center mx-auto" /></p>
</li>
</ol>
<h3 id="heading-step-11-now-create-two-ec2-instances-one-for-the-public-subnet-and-another-for-the-private">Step 11:  <strong>Now create two EC2 instances, one for the public subnet and another for the private.</strong></h3>
<ol>
<li><p>Search EC2 and select instances -&gt; Launch instance</p>
<ul>
<li><p>Name: myPublic</p>
</li>
<li><p>Create key pair (give any name and select pem for Linux user and ppk for putty user)</p>
</li>
<li><p>Network setting -&gt; Edit</p>
</li>
<li><p>VPC: select that we created above</p>
</li>
<li><p>subnet: public subnet since it is public instance</p>
</li>
<li><p>Auto-assign public IP: enable</p>
</li>
<li><p>*Leave all default or you can add as other thing as required.</p>
</li>
</ul>
</li>
<li><p>Again Launch instance for private subnet</p>
<ul>
<li><p>Name: myPrivate</p>
</li>
<li><p>Select same key pair (if same key selected convert ppk file to pem if putty used) or create new key (give any name and select pem)</p>
</li>
<li><p>Network setting -&gt; Edit</p>
</li>
<li><p>VPC: select that we created above</p>
</li>
<li><p>subnet: private subnet since it is private instance</p>
</li>
<li><p>Auto-assign public IP: disable</p>
</li>
<li><p>*Leave all default or you can add other things as required.</p>
</li>
</ul>
</li>
</ol>
<h3 id="heading-step-12-connect-to-the-private-instance-using-public-instance">Step 12:  Connect to the private instance using public instance</h3>
<ol>
<li><p><strong>Connect public instance using a key that we created.</strong></p>
</li>
<li><p>create new file <code>nano new.pem</code> and paste content of pem file that we downloaded (or converted from ppk file)</p>
</li>
<li><p>Give permission as</p>
<pre><code class="lang-plaintext"> chmod 400 new.pem
</code></pre>
</li>
<li><p>Connect to private instance from public instance</p>
<pre><code class="lang-plaintext"> ssh -i new.pem ec2-user@&lt;private-ip-of-myPrivate-instance&gt;
</code></pre>
<p> Now check <code>ping google.com</code> to confirm private instance connected with internet or not</p>
</li>
</ol>
]]></content:encoded></item><item><title><![CDATA[AWS Re/start- the opportunity]]></title><description><![CDATA[AWS(Amazon Web Services) is the most used widely used cloud which gives you more than 200 fully featured services from data centers globally. AWS re/start is a free cohort-based training of 12 weeks provided by AWS for preparing individuals for cloud...]]></description><link>https://blog.lokendrabhat.com.np/aws-restart-the-opportunity</link><guid isPermaLink="true">https://blog.lokendrabhat.com.np/aws-restart-the-opportunity</guid><category><![CDATA[AWS]]></category><category><![CDATA[Cloud]]></category><dc:creator><![CDATA[Lokendra Bhat]]></dc:creator><pubDate>Mon, 15 May 2023 13:45:40 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1686486501333/fa822087-29f2-4400-a0ad-0dba45fde965.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>AWS(Amazon Web Services) is the most used widely used cloud which gives you more than 200 fully featured services from data centers globally. AWS re/start is a free cohort-based training of 12 weeks provided by AWS for preparing individuals for cloud careers.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684158080849/130ccb32-f5d3-48e9-9646-a70a6d7ef09c.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-benefits-of-aws-restart">Benefits of AWS-Restart</h2>
<ul>
<li><p>Access free AWS cloud skills training</p>
</li>
<li><p>Build skills aligned with AWS certification</p>
</li>
<li><p>Connect with employers and launch your career</p>
</li>
<li><p>and many more</p>
</li>
</ul>
<h2 id="heading-aws-restart-course-agenda">AWS-re/start Course Agenda:</h2>
<ul>
<li><p>Introduction to Cloud Foundation</p>
</li>
<li><p>Linux</p>
</li>
<li><p>Networking</p>
</li>
<li><p>Security</p>
</li>
<li><p>Python Programming</p>
</li>
<li><p>Databases</p>
</li>
<li><p>About AWS services</p>
</li>
<li><p>Evaluation and Exam preparation</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1684157363910/5551663b-3226-497f-a2d2-40363ec18925.jpeg" alt class="image--center mx-auto" /></p>
</li>
</ul>
<h1 id="heading-lets-go">Let's Go!!!</h1>
<h1 id="heading-launch-your-career-with-a-unique-idea">Launch your career with a unique IDEA.</h1>
<p>for more information regarding cloud and AWS, you can visit</p>
<ul>
<li><p><a target="_blank" href="https://aws.amazon.com/">https://aws.amazon.com/</a></p>
</li>
<li><p><a target="_blank" href="https://docs.aws.amazon.com/">https://docs.aws.amazon.com/</a></p>
</li>
</ul>
<p>[ copyright: AWS ]</p>
]]></content:encoded></item></channel></rss>