<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Eden Jose</title>
    <description>The latest articles on DEV Community by Eden Jose (@jeden).</description>
    <link>https://dev.to/jeden</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F350730%2F9eb9ff9f-e2a6-4300-b01d-801939abde63.jpg</url>
      <title>DEV Community: Eden Jose</title>
      <link>https://dev.to/jeden</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jeden"/>
    <language>en</language>
    <item>
      <title>AWS, Kubernetes, and All Things DevOps</title>
      <dc:creator>Eden Jose</dc:creator>
      <pubDate>Sat, 01 Jul 2023 03:45:10 +0000</pubDate>
      <link>https://dev.to/jeden/aws-kubernetes-and-all-things-devops-2hfl</link>
      <guid>https://dev.to/jeden/aws-kubernetes-and-all-things-devops-2hfl</guid>
      <description>&lt;p&gt;I've been away for quite some time. Been busy with a lot of transitions-at home, at work, in life. &lt;/p&gt;

&lt;p&gt;Been working on some projects but I've been posting them in Github as it's easy to manage and consolidate all projects into one single place. I will probably create some write-ups here in Dev.to on some of the interesting projects in my Github repositories, but in the meantime, here are some of the resources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/joseeden/All-Things-DevOps/blob/master/README.md"&gt;All Things DevOps&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/joseeden/All-Things-Docker-and-Kubernetes/blob/master/README.md"&gt;All Things Docker and Kubernetes&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/joseeden/All-Things-Terraform/blob/master/README.md"&gt;All Things Terraform&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/joseeden/notes-aws-sysops/blob/master/README.md"&gt;Notes - AWS SysOps Administrator Associate (SOA-C01)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;





&lt;div class="ltag__user ltag__user__id__350730"&gt;
    &lt;a href="/jeden" class="ltag__user__link profile-image-link"&gt;
      &lt;div class="ltag__user__pic"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iFJ114bh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--eEDFpfUC--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/350730/9eb9ff9f-e2a6-4300-b01d-801939abde63.jpg" alt="jeden image"&gt;
      &lt;/div&gt;
    &lt;/a&gt;
  &lt;div class="ltag__user__content"&gt;
    &lt;h2&gt;
&lt;a class="ltag__user__link" href="/jeden"&gt;Eden Jose&lt;/a&gt;Follow
&lt;/h2&gt;
    &lt;div class="ltag__user__summary"&gt;
      &lt;a class="ltag__user__link" href="/jeden"&gt;A cloud enthusiast, an IT Professional, and a problem-solver.
I am either learning something new, running a mile, or planning my next 100 days.
&lt;/a&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;


</description>
      <category>devops</category>
      <category>aws</category>
      <category>cloud</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Setting my bash prompt for WSL</title>
      <dc:creator>Eden Jose</dc:creator>
      <pubDate>Sun, 09 Jan 2022 11:55:36 +0000</pubDate>
      <link>https://dev.to/jeden/setting-my-bash-prompt-for-wsl-131</link>
      <guid>https://dev.to/jeden/setting-my-bash-prompt-for-wsl-131</guid>
      <description>&lt;p&gt;This is just a dump of my settings for bash prompt for my WSL terminal. I didn't like to show the whole path since it takes up the whole line already but I do want to see the directory where I'm currently at.&lt;/p&gt;

&lt;p&gt;Appended this to the bottom of &lt;strong&gt;~/.bashrc&lt;/strong&gt; and then re-opened my terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;vim ~/.bashrc

&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;PS1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"[&lt;/span&gt;&lt;span class="se"&gt;\[\e&lt;/span&gt;&lt;span class="s2"&gt;]0;&lt;/span&gt;&lt;span class="se"&gt;\u&lt;/span&gt;&lt;span class="s2"&gt;@&lt;/span&gt;&lt;span class="se"&gt;\h&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="se"&gt;\W\]&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;debian_chroot&lt;/span&gt;:+&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$debian_chroot&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\[\0&lt;/span&gt;&lt;span class="s2"&gt;33[01;32m&lt;/span&gt;&lt;span class="se"&gt;\]\u&lt;/span&gt;&lt;span class="s2"&gt;@&lt;/span&gt;&lt;span class="se"&gt;\h\[\0&lt;/span&gt;&lt;span class="s2"&gt;33[00m&lt;/span&gt;&lt;span class="se"&gt;\]&lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="se"&gt;\[\0&lt;/span&gt;&lt;span class="s2"&gt;33[01;34m&lt;/span&gt;&lt;span class="se"&gt;\]&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="se"&gt;\W\[\0&lt;/span&gt;&lt;span class="s2"&gt;33[00m&lt;/span&gt;&lt;span class="se"&gt;\]&lt;/span&gt;&lt;span class="s2"&gt;]&lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsohk3mvpk7nrid1a97q6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsohk3mvpk7nrid1a97q6.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also, the &lt;strong&gt;desktop&lt;/strong&gt; and &lt;strong&gt;dloads&lt;/strong&gt; are aliases I added to the same file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;addalias

&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;addalias&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'sudo vi /home/joseeden/.bashrc'&lt;/span&gt;
&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;desktop&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'cd /mnt/c/Users/Eden\ Jose/Desktop'&lt;/span&gt;
&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;dloads&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'cd /mnt/c/Users/Eden\ Jose/Downloads'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>devjournal</category>
      <category>programming</category>
      <category>linux</category>
      <category>devops</category>
    </item>
    <item>
      <title>Attaching multiple EBS volumes to the same EC2 instance</title>
      <dc:creator>Eden Jose</dc:creator>
      <pubDate>Mon, 06 Dec 2021 04:22:07 +0000</pubDate>
      <link>https://dev.to/jeden/attaching-multiple-ebs-volumes-to-the-same-ec2-instance-3hbd</link>
      <guid>https://dev.to/jeden/attaching-multiple-ebs-volumes-to-the-same-ec2-instance-3hbd</guid>
      <description>&lt;p&gt;Just a short note. I created three EBS volumes to be used for my storage labs in Linux. I was going to attach them all at the same time to a single instance but the &lt;strong&gt;Attach volume&lt;/strong&gt; is greyed out in the &lt;strong&gt;Actions&lt;/strong&gt; tab.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F79pv469ys1hcjyozatin.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F79pv469ys1hcjyozatin.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, if you mark them one by one, the &lt;strong&gt;Attach volume&lt;/strong&gt; can be selected.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F84v5svflf5tsqt23ore7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F84v5svflf5tsqt23ore7.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h4&gt;
  
  
  Summary
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Multiple EBS volumes can be deleted at the same time&lt;/li&gt;
&lt;li&gt;Multiple EBS volumes can be attached to the same instance, but only one at a time&lt;/li&gt;
&lt;li&gt;Snapshots can be created for multiple volumes simultaneously&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  P.S.
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;AWS frequently changes their UI and functionalities so they may allow attaching volumes simultaneously in the future.&lt;/li&gt;
&lt;li&gt;Also, this is just trivial matter since this probably won't matter if the volumes and instances are spun up in an automated way&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>aws</category>
      <category>cloud</category>
      <category>devops</category>
      <category>devjournal</category>
    </item>
    <item>
      <title>EBS Volume stuck in "Attaching"</title>
      <dc:creator>Eden Jose</dc:creator>
      <pubDate>Mon, 06 Dec 2021 00:29:17 +0000</pubDate>
      <link>https://dev.to/jeden/ebs-volume-stuck-in-attaching-5eo8</link>
      <guid>https://dev.to/jeden/ebs-volume-stuck-in-attaching-5eo8</guid>
      <description>&lt;p&gt;Came across this error when I was doing labs for storage management in Linux. I was having issues on not being able to format the disks, so I finally decided,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="s2"&gt;"Ah, f*ck it. Imma just delete this volume and slap a new, 
fresh one in its place."&lt;/span&gt;


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

&lt;/div&gt;




&lt;h3&gt;
  
  
  Detaching and Force Detaching
&lt;/h3&gt;

&lt;p&gt;So there I went. Entered the AWS console and then to the EBS menu, selected my volume and deleted it. After detaching the volume, it still showed &lt;strong&gt;"In-use"&lt;/strong&gt; volume state. Refreshed the menu a couple of times and it still showed the same. If the detachment was successful, it should have instead show &lt;strong&gt;"Available"&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feo6o18ql29wejyvjspn8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feo6o18ql29wejyvjspn8.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another f*ck-it moment.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="s2"&gt;"Ah, f*ck it. Imma force delete this sh*t."&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Selected the volume, hit &lt;strong&gt;Actions&lt;/strong&gt;, and chose &lt;strong&gt;Force detach volume&lt;/strong&gt;.&lt;br&gt;
Note that it will prompt you to confirm by typing in &lt;em&gt;detach&lt;/em&gt; on the prompt.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi70s5eklfoi70a3dbaoi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi70s5eklfoi70a3dbaoi.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fufciuyufdajjqgywxwak.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fufciuyufdajjqgywxwak.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Afterwards, I deleted the volume so I can create a new one with the same device name.&lt;/p&gt;




&lt;h3&gt;
  
  
  Creating and Attaching the new EBS volume
&lt;/h3&gt;

&lt;p&gt;Created a new EBS volume and gave it the same &lt;strong&gt;Name&lt;/strong&gt;. Attached it to the same EC2 instance and reused the same device name &lt;strong&gt;/dev/sdc&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcjkdsfno39twr2nbbwv0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcjkdsfno39twr2nbbwv0.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  EBS Menu vs. EC2 Instance Menu
&lt;/h3&gt;

&lt;p&gt;From the EBS volume menu, the new volume is immediately transitioned to &lt;strong&gt;"In-use"&lt;/strong&gt; state.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx9we5a54hiireghvtkpv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx9we5a54hiireghvtkpv.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, it still showing as &lt;strong&gt;Attaching&lt;/strong&gt; from the EC2 instance menu. Refreshed the menu a couple of times and it still shows the same.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpw8owqm4gxhphcz67do2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpw8owqm4gxhphcz67do2.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From the terminal, I also can't see the new &lt;em&gt;/dev/xvdc&lt;/em&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

eden@tst-rhel:~ &lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;fdisk /dev/xvdc &lt;span class="nt"&gt;-l&lt;/span&gt;
fdisk: cannot open /dev/xvdc: Input/output error


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

&lt;/div&gt;




&lt;h3&gt;
  
  
  Google Time
&lt;/h3&gt;

&lt;p&gt;Went online and immediately found this helpful article from AWS themselves. It carefully explained what may have caused the issue. Breezed through it and found the culprit:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The block device driver didn't release the device name&lt;/strong&gt;&lt;br&gt;
If a user has initiated a forced detach of an Amazon EBS volume, the block device driver of the Amazon EC2 instance might not immediately release the device name for reuse. Attempting to use that device name when attaching a volume causes the volume to be stuck in the attaching state. You must either choose a different device name or reboot the instance.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Reboot
&lt;/h4&gt;

&lt;p&gt;So I went and rebooted the instance. After it went back, i checked again the &lt;strong&gt;Storage&lt;/strong&gt; tab in the &lt;strong&gt;Instance Summary&lt;/strong&gt; panel. But now it showed a new error at the bottom. It also still shows the specific volume stuck in "attaching" state&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh9x0f0s3rx7yj8jgvl0t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh9x0f0s3rx7yj8jgvl0t.png" alt="Image description"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h4&gt;
  
  
  Restart
&lt;/h4&gt;

&lt;p&gt;Going back to the AWS articles, it suggested to do a restart.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If these steps don’t resolve the issue, or if you must use the device name that isn't working, try the following procedures:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reboot the instance.&lt;/li&gt;
&lt;li&gt;Stop and start the instance to migrate it to new underlying hardware. Keep in mind that instance store data is lost when you stop and start an instance. If your instance is instance store-backed or has instance store volumes containing data, the data is lost when you stop the instance.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Wait, hold up!
&lt;/h4&gt;

&lt;p&gt;After re-reading the AWS article, I went back to the AWS Console to restart the instance. And what do you know. The new error is gone, the volume has also changed to &lt;strong&gt;"Attached"&lt;/strong&gt; state.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1vi6c8gndgcvvzyn1r5o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1vi6c8gndgcvvzyn1r5o.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also can see it from the terminal&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

eden@tst-rhel:~ &lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;fdisk /dev/xvdc &lt;span class="nt"&gt;-l&lt;/span&gt;
Disk /dev/xvdc: 100 GiB, 107374182400 bytes, 209715200 sectors
Units: sectors of 1 &lt;span class="k"&gt;*&lt;/span&gt; 512 &lt;span class="o"&gt;=&lt;/span&gt; 512 bytes
Sector size &lt;span class="o"&gt;(&lt;/span&gt;logical/physical&lt;span class="o"&gt;)&lt;/span&gt;: 512 bytes / 512 bytes
I/O size &lt;span class="o"&gt;(&lt;/span&gt;minimum/optimal&lt;span class="o"&gt;)&lt;/span&gt;: 512 bytes / 512 bytes


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

&lt;/div&gt;

&lt;p&gt;That's it.&lt;/p&gt;




&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://aws.amazon.com/premiumsupport/knowledge-center/ebs-stuck-attaching/" rel="noopener noreferrer"&gt;Why is my Amazon EBS volume stuck in the "attaching" state?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>aws</category>
      <category>cloud</category>
      <category>devops</category>
      <category>devjournal</category>
    </item>
    <item>
      <title>Iptables and locking myself out</title>
      <dc:creator>Eden Jose</dc:creator>
      <pubDate>Sun, 28 Nov 2021 20:28:29 +0000</pubDate>
      <link>https://dev.to/jeden/iptables-and-locking-myself-out-nhp</link>
      <guid>https://dev.to/jeden/iptables-and-locking-myself-out-nhp</guid>
      <description>&lt;ul&gt;
&lt;li&gt;What I'm using&lt;/li&gt;
&lt;li&gt;
Possible solutions

&lt;ul&gt;
&lt;li&gt;SSH Client&lt;/li&gt;
&lt;li&gt;EC2 Instance Connect&lt;/li&gt;
&lt;li&gt;Session Manager&lt;/li&gt;
&lt;li&gt;EC2 Serial Console&lt;/li&gt;
&lt;li&gt;Detaching the root volume and attaching to a second instance&lt;/li&gt;
&lt;li&gt;EC2 Support&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;What really solved it!&lt;/li&gt;

&lt;li&gt;

Lessons Learned

&lt;ul&gt;
&lt;li&gt;
Decent iptables - A Working Rule Set for iptables per your requirements

&lt;ul&gt;
&lt;li&gt;Inbound filtering&lt;/li&gt;
&lt;li&gt;Outbound filtering&lt;/li&gt;
&lt;li&gt;Forward filtering:&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;li&gt;References&lt;/li&gt;

&lt;/ul&gt;




&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Summary: Locked myself out via my own iptables policy. Other possible ways to connect are laid out but the one that worked is explained in the&lt;/em&gt; &lt;strong&gt;&lt;em&gt;What really solved it&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;section.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  What I'm using
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;EC2 t2.xlarge instance with Elastic IP&lt;/li&gt;
&lt;li&gt;I haven't installed any AWS-related agents before the incident&lt;/li&gt;
&lt;li&gt;Security groups are set to allow only connections from either my IP or the security group itself&lt;/li&gt;
&lt;li&gt;I didn't modify the default parameters set in the &lt;strong&gt;iptables-config&lt;/strong&gt; file&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;I was playing around with DROP and REJECT on iptables and I'm using the "&lt;strong&gt;--protocol&lt;/strong&gt;" as criteria to apply policy on. Since I've used udp and icmp already, I tried to drop tcp connections - &lt;strong&gt;bad idea&lt;/strong&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;iptables &lt;span class="nt"&gt;-A&lt;/span&gt; INPUT &lt;span class="nt"&gt;--protocol&lt;/span&gt; tcp &lt;span class="nt"&gt;--in-intersection&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;After some searching, I learned that I'm basically fcked up. From a Stackoverflow discussion &lt;a href="https://askubuntu.com/questions/909984/how-to-fix-iptables-if-i-have-blocked-all-incoming-and-outgoing-connections" rel="noopener noreferrer"&gt;How to fix iptables if i have blocked all incoming and outgoing connections?&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;From comments, we've established this is on an Amazon AWS EC2 instance, and that you've locked yourself out from SSH access remotely. By using Amazon EC2, you're going to have a bit of a headache here. There's no real serial/console mode for access, nor anyone who can just 'fix' it, and by disabling all connections as you did, you've locked yourself out completely.&lt;/p&gt;

&lt;p&gt;You don't really have much of a solution here but to destroy the EC2 instance and start over.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;While this was helpful, note that this answer was posted in the Stackoverflow site last 2017 and there have been other ways created to connect to the instance. To see the options on how to connect to your EC2 instance, select your instance and click &lt;strong&gt;Connect&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fimbh63ha3rur8wlt62n2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fimbh63ha3rur8wlt62n2.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Possible solutions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  SSH Client
&lt;/h3&gt;

&lt;p&gt;I've already used up &lt;strong&gt;SSH client&lt;/strong&gt; when I blocked myself through iptables, so that leaves me with 3 more options.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8xzh7vsd80azayp7cghw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8xzh7vsd80azayp7cghw.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  EC2 Instance Connect
&lt;/h3&gt;

&lt;p&gt;This didn't worked out as well since I needed to have &lt;strong&gt;EC2 Instance Connect&lt;/strong&gt; installed on the machine before anything else. I tried to go the link provided in the error message &lt;a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-connect-set-up.html?icmpid=docs_ec2_console#ec2-instance-connect-setup-security-group" rel="noopener noreferrer"&gt;Task 1: Configure network access to an instance.&lt;/a&gt; but it tackled more about security groups which isn't the one that's restricting me.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F25s0dd7js60w65y7kk4n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F25s0dd7js60w65y7kk4n.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Session Manager
&lt;/h3&gt;

&lt;p&gt;This would have been really useful because this uses SSH to connect to the instance. However, like EC2 Instance Connect, the Session Manager needs to be installed on the machine before anything else. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: Have this installed upon launching your instance or better yet define it in the startup script. Steps on how to install Session Manager in Linux can be read &lt;a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-install-ssm-agent.html" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fupx3chay1b31kv6zxsej.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fupx3chay1b31kv6zxsej.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  EC2 Serial Console
&lt;/h3&gt;

&lt;p&gt;This was a new one which I haven't seen last year during my review for the Associates certification exam. It required me to allow the account to use the EC2 Serial Console so I simply clicked &lt;strong&gt;Managed access&lt;/strong&gt; and then ticked the &lt;strong&gt;Allow&lt;/strong&gt; box and &lt;strong&gt;Update&lt;/strong&gt; on the next page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F14ulsruluwr25jivkrco.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F14ulsruluwr25jivkrco.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhvkigd3zknyxhrvzuuq4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhvkigd3zknyxhrvzuuq4.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Going back to the previous EC2 instances landing page, selected my instance and hit &lt;strong&gt;Connect&lt;/strong&gt; to see the &lt;strong&gt;EC2 Serial Console&lt;/strong&gt; tab again. This time it showed another message - "&lt;strong&gt;This instance type is not supported for the EC2 serial console.&lt;/strong&gt;"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F60adp2yendf4qpy815x7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F60adp2yendf4qpy815x7.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I went over the provided links and breezed through them. After allowing EC2 serial console access to the account, the instance type I'm using should also one of the &lt;a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html?icmpid=docs_ec2_console#ec2-nitro-instances" rel="noopener noreferrer"&gt;supported instance type - Nitro&lt;/a&gt;. These are references you may check out:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html?icmpid=docs_ec2_console#ec2-nitro-instances" rel="noopener noreferrer"&gt;Instances built on the Nitro System&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-resize.html?icmpid=docs_ec2_console" rel="noopener noreferrer"&gt;Change the instance type&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Detaching the root volume and attaching to a second instance
&lt;/h3&gt;

&lt;p&gt;This is actually an interesting method though I decided not to opt for this because I already found a solution - a really simpel one actually!&lt;br&gt;
Keep scrolling down to read about it.&lt;/p&gt;

&lt;p&gt;Also, I might create a separate article about this method.&lt;/p&gt;

&lt;h3&gt;
  
  
  EC2 Support
&lt;/h3&gt;

&lt;p&gt;When all else fail, reach out to support. My free tier account has already expired years ago and I'm currently using AWS free credits I've obtained by joining the &lt;strong&gt;AWS Community Builders&lt;/strong&gt; program. I am pretty sure that I'll have someone from their end answered some of my inquiries in the next 6 hours but I decided to not take the rouble of raising any support requests to them.&lt;/p&gt;

&lt;p&gt;Since my focus at the moment is doing labs for the RHCSA topics and not on AWS, going through the linked documentations would be a rabbithole and would tend to be more complicated that just by simply deleting this instance and spinning up a fresh one.&lt;/p&gt;

&lt;p&gt;Having said, I am considering to destroy it and start over. But this time, I'm having SSM Session Manager installed!&lt;/p&gt;




&lt;h2&gt;
  
  
  What really solved it!
&lt;/h2&gt;

&lt;p&gt;I was almost on the verge of completely deleting the instance but then I remembered that iptables has a default config file called &lt;strong&gt;iptables-config&lt;/strong&gt;, which contains two important parameters:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="c"&gt;# Save current firewall rules on stop.&lt;/span&gt;
&lt;span class="c"&gt;#   Value: yes|no,  default: no&lt;/span&gt;
&lt;span class="c"&gt;# Saves all firewall rules to /etc/sysconfig/iptables if firewall gets stopped&lt;/span&gt;
&lt;span class="c"&gt;# (e.g. on system shutdown).&lt;/span&gt;
&lt;span class="nv"&gt;IPTABLES_SAVE_ON_STOP&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"no"&lt;/span&gt;

&lt;span class="c"&gt;# Save current firewall rules on restart.&lt;/span&gt;
&lt;span class="c"&gt;#   Value: yes|no,  default: no&lt;/span&gt;
&lt;span class="c"&gt;# Saves all firewall rules to /etc/sysconfig/iptables if firewall gets&lt;/span&gt;
&lt;span class="c"&gt;# restarted.&lt;/span&gt;
&lt;span class="nv"&gt;IPTABLES_SAVE_ON_RESTART&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"no"&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Basically what this two parameters meant is, if these two are set to "no", then rules will not persists when the machine is stopped or restarted. This means rules will be flushed out - yes!&lt;/p&gt;

&lt;p&gt;So, after some restarting, I was able to log in again! All rules are also flushed out!&lt;/p&gt;

&lt;p&gt;Didn't thought that a &lt;strong&gt;simple restart&lt;/strong&gt; would save the day once again. Whew!&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo  &lt;/span&gt;iptables &lt;span class="nt"&gt;-L&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt;
Chain INPUT &lt;span class="o"&gt;(&lt;/span&gt;policy ACCEPT 379 packets, 47895 bytes&lt;span class="o"&gt;)&lt;/span&gt;
 pkts bytes target     prot opt &lt;span class="k"&gt;in     &lt;/span&gt;out     &lt;span class="nb"&gt;source               &lt;/span&gt;destination

Chain FORWARD &lt;span class="o"&gt;(&lt;/span&gt;policy ACCEPT 0 packets, 0 bytes&lt;span class="o"&gt;)&lt;/span&gt;
 pkts bytes target     prot opt &lt;span class="k"&gt;in     &lt;/span&gt;out     &lt;span class="nb"&gt;source               &lt;/span&gt;destination

Chain OUTPUT &lt;span class="o"&gt;(&lt;/span&gt;policy ACCEPT 486 packets, 50206 bytes&lt;span class="o"&gt;)&lt;/span&gt;
 pkts bytes target     prot opt &lt;span class="k"&gt;in     &lt;/span&gt;out     &lt;span class="nb"&gt;source               &lt;/span&gt;destination


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

&lt;/div&gt;




&lt;h2&gt;
  
  
  Lesson Learned
&lt;/h2&gt;

&lt;p&gt;Going back to the original Stackoverflow discussion I've read earlier, it provided some important pointers which I thoguht to include here. I'm putting the original thread in the references section at the bottom.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use the EC2 security group firewall instead&lt;/strong&gt;. This is a little easier to configure, and it's already there without any additional configuration - it's part of the EC2 infrastructure where you have to permit ports to actually get to the EC2 instance. You also aren't going to lock yourself out as easily (though you can get locked out, it's trivial to fix it then because you just allow port 22 again in the rule set from the Amazon EC2 settings panel, provided you don't mess with iptables as well).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use a decent iptables&lt;/strong&gt; ruleset and don't log out from PuTTY on your EC2 until you are absolutely sure the rules you've put in place don't completely torpedo your access to the system.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Recommended to &lt;strong&gt;not mess with the default policies&lt;/strong&gt; on a server, because it has some... evils... if not done correctly, and I usually only filter ingress traffic and FORWARD traffic, and permit Outgoing traffic because of time sync servers,&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Decent iptables - A Working Rule Set for iptables per your requirements
&lt;/h3&gt;

&lt;p&gt;You don't need to type lines that have a # at the beginning, those're just my comments explaining what each command does. Also, replace YOUR.IP.ADDRESS.HERE with your actual IP address, where it shows up below.&lt;/p&gt;

&lt;h4&gt;
  
  
  Inbound filtering
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="c"&gt;# Permit localhost to communicate with itself.&lt;/span&gt;
iptables &lt;span class="nt"&gt;-A&lt;/span&gt; INPUT &lt;span class="nt"&gt;-i&lt;/span&gt; lo &lt;span class="nt"&gt;-j&lt;/span&gt; ACCEPT
&lt;span class="c"&gt;# Permit already established connection traffic and related traffic&lt;/span&gt;
iptables &lt;span class="nt"&gt;-A&lt;/span&gt; INPUT &lt;span class="nt"&gt;-m&lt;/span&gt; conntrack &lt;span class="nt"&gt;--ctstate&lt;/span&gt; RELATED,ESTABLISHED &lt;span class="nt"&gt;-j&lt;/span&gt; ACCEPT
&lt;span class="c"&gt;# Permit new SSH connections into the system from trusted IP address&lt;/span&gt;
iptables &lt;span class="nt"&gt;-A&lt;/span&gt; INPUT &lt;span class="nt"&gt;-p&lt;/span&gt; tcp &lt;span class="nt"&gt;--dport&lt;/span&gt; 22 &lt;span class="nt"&gt;-s&lt;/span&gt; YOUR.IP.ADDRESS.HERE &lt;span class="nt"&gt;-m&lt;/span&gt; conntrack &lt;span class="nt"&gt;--ctstate&lt;/span&gt; NEW &lt;span class="nt"&gt;-j&lt;/span&gt; ACCEPT
&lt;span class="c"&gt;# Permit all other traffic from trusted IP Address&lt;/span&gt;
iptables &lt;span class="nt"&gt;-A&lt;/span&gt; INPUT &lt;span class="nt"&gt;-s&lt;/span&gt; YOUR.IP.ADDRESS.HERE &lt;span class="nt"&gt;-j&lt;/span&gt; ACCEPT
&lt;span class="c"&gt;# Drop all other traffic&lt;/span&gt;
iptables &lt;span class="nt"&gt;-A&lt;/span&gt; INPUT &lt;span class="nt"&gt;-j&lt;/span&gt; DROP


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

&lt;/div&gt;
&lt;h4&gt;
  
  
  Outbound filtering
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="c"&gt;# Allow Localhost to itself&lt;/span&gt;
iptables &lt;span class="nt"&gt;-A&lt;/span&gt; OUTPUT &lt;span class="nt"&gt;-i&lt;/span&gt; lo &lt;span class="nt"&gt;-j&lt;/span&gt; ACCEPT
&lt;span class="c"&gt;# Allow RELATED,ESTABLISHED state traffic (related to Inbound for example)&lt;/span&gt;
iptables &lt;span class="nt"&gt;-A&lt;/span&gt; OUTPUT &lt;span class="nt"&gt;-m&lt;/span&gt; conntrack &lt;span class="nt"&gt;--ctstate&lt;/span&gt; RELATED,ESTABLISHED &lt;span class="nt"&gt;-j&lt;/span&gt; ACCEPT
&lt;span class="c"&gt;# Allow all other traffic to trusted IP address&lt;/span&gt;
iptables &lt;span class="nt"&gt;-A&lt;/span&gt; OUTPUT &lt;span class="nt"&gt;-d&lt;/span&gt; YOUR.IP.ADDRESS.HERE &lt;span class="nt"&gt;-j&lt;/span&gt; ACCEPT
&lt;span class="c"&gt;# Drop all other unpermitted outbound traffic.&lt;/span&gt;
iptables &lt;span class="nt"&gt;-A&lt;/span&gt; OUTPUT &lt;span class="nt"&gt;-j&lt;/span&gt; DROP


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

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;Warning: This will block access to the update servers, time sync servers, etc. so ONLY filter on Outbound if you absolutely need to, otherwise don't do this section at all&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Forward filtering:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="c"&gt;# Drop FORWARD target traffic, we don't need it&lt;/span&gt;
iptables &lt;span class="nt"&gt;-A&lt;/span&gt; FORWARD &lt;span class="nt"&gt;-j&lt;/span&gt; DROP


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

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;NOTE: Unless you really need to restrict things like forwarding traffic to the Internet via a tunnel or VPN to your server as a 'proxy' to the 'net, you really don't need to mess with the FORWARD rulesets, so I would suggest not doing this because nothing else is really going to use this function or ever land in this rule set table&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://askubuntu.com/questions/909984/how-to-fix-iptables-if-i-have-blocked-all-incoming-and-outgoing-connections" rel="noopener noreferrer"&gt;How to fix iptables if i have blocked all incoming and outgoing connections?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://serverfault.com/questions/88086/should-you-use-iptables-with-ec2-instances" rel="noopener noreferrer"&gt;Should you use iptables with EC2 instances?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>devjournal</category>
      <category>devops</category>
      <category>linux</category>
      <category>aws</category>
    </item>
    <item>
      <title>How to create cover images in dev.to with the title and author's name?</title>
      <dc:creator>Eden Jose</dc:creator>
      <pubDate>Sun, 28 Nov 2021 18:58:07 +0000</pubDate>
      <link>https://dev.to/jeden/how-to-create-cover-images-in-devto-with-the-title-and-authors-name-5g69</link>
      <guid>https://dev.to/jeden/how-to-create-cover-images-in-devto-with-the-title-and-authors-name-5g69</guid>
      <description>&lt;p&gt;I've been seeing articles here in dev.to with the banner/cover image showing the article's title, the publish date, and the author's name, plus the DEV logo a the right side, similar to the one below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--g97hsCvD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1i5hykbgacsjsilr6la4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--g97hsCvD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1i5hykbgacsjsilr6la4.png" alt="Image description" width="880" height="468"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;More examples:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2cT5Zeq2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l0mmgvl0vyfl7ccqva9l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2cT5Zeq2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l0mmgvl0vyfl7ccqva9l.png" alt="Image description" width="740" height="539"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I followed the instruction on this &lt;a href="https://dev.to/dev3l/comment/i87"&gt;link&lt;/a&gt; but I'm having no luck in creating the "auto-generated banner from the article's title". &lt;/p&gt;

&lt;p&gt;I did find this link about how "automated images" are created but I was wondering if there's other options that other people here dev.to is using?&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>beginners</category>
      <category>devjournal</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>EC2 Userdata script: Changing EC2 instance default username + run commands </title>
      <dc:creator>Eden Jose</dc:creator>
      <pubDate>Sun, 28 Nov 2021 18:31:55 +0000</pubDate>
      <link>https://dev.to/jeden/changing-ec2-instance-default-username-run-commands-on-startup-4l04</link>
      <guid>https://dev.to/jeden/changing-ec2-instance-default-username-run-commands-on-startup-4l04</guid>
      <description>&lt;p&gt;This is a short note on how to change the username that your EC2 instance uses upon startup. If you're using RHEL or CentOS, you probably see that the default username you see when you log in to your instance for the first time is &lt;strong&gt;ec2-user&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You can change this, plus run other commands during startup by using the script below and putting it on the &lt;strong&gt;User Data&lt;/strong&gt; field during the creation of instance.&lt;/p&gt;

&lt;p&gt;In this example, I'm setting the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;default username: jeden&lt;/li&gt;
&lt;li&gt;hostname: tst-rhel&lt;/li&gt;
&lt;li&gt;format of the shell prompt
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#cloud-config&lt;/span&gt;
system_info:
  default_user:
    name: eden

runcmd:
 - &lt;span class="s1"&gt;'sudo hostnamectl set-hostname tstrhel'&lt;/span&gt;
 - &lt;span class="s1"&gt;'sudo sed -i "s/localhost/localhost tstrhel/" /etc/hosts'&lt;/span&gt;
 - &lt;span class="s1"&gt;'echo "PS1=\"[\u@\H: \W] $ \"" &amp;gt;&amp;gt; .bashrc'&lt;/span&gt;
 - &lt;span class="s1"&gt;'sudo yum update -y'&lt;/span&gt;
 - &lt;span class="s1"&gt;'sudo yum install -y vim nano wget bash-completion firewalld'&lt;/span&gt;
 - &lt;span class="s1"&gt;'sudo yum install -y epel-release'&lt;/span&gt;
 - &lt;span class="s1"&gt;'sudo yum install -y python3'&lt;/span&gt;
 - &lt;span class="s1"&gt;'sudo yum install -y python3-pip python-devel'&lt;/span&gt;
 - &lt;span class="s1"&gt;'sudo yum groupinstall -y "development tools"'&lt;/span&gt;
 - &lt;span class="s1"&gt;'sudo pip install --upgrade pip'&lt;/span&gt;
 - &lt;span class="s1"&gt;'sudo yum install -y policycoreutils-python-utils'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You may add more commands to be ran during startup by appending them in the &lt;strong&gt;runcmd&lt;/strong&gt; section.&lt;/p&gt;

&lt;h4&gt;
  
  
  Note:
&lt;/h4&gt;

&lt;p&gt;Some commands may not be ran during startup especially if the command requires that bootup process is done before it is executed.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>devops</category>
      <category>devjournal</category>
      <category>linux</category>
    </item>
    <item>
      <title>A Shift in Thinking</title>
      <dc:creator>Eden Jose</dc:creator>
      <pubDate>Thu, 25 Nov 2021 04:17:37 +0000</pubDate>
      <link>https://dev.to/jeden/a-shift-in-thinking-355i</link>
      <guid>https://dev.to/jeden/a-shift-in-thinking-355i</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;TLDR: And that I think is the real shift of thinking:&lt;br&gt;
When you shift from being a learner to a problem-solver.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;I realized that when you finished a course and learn some stuff and then work on actual projects, you seldom go back to the course and re-watch particular sections related to the issue you're troubleshooting.&lt;/p&gt;

&lt;p&gt;Instead, you either a) go to your own notes or documentation to see if you've resolved it before (if you trust your documentation well enough), or you take the much easier and quicker route, b) you google it or search for sample use-cases in Youtube.&lt;/p&gt;

&lt;p&gt;So, I think structured courses are really great when you're at the stage of discovery. But when you are trying to implement it to solve your own problems, you follow your own instinct to google it and hope someone has raised the same specific issues in Stackoverflow or hope that someone has made a video of it in Youtube.&lt;/p&gt;

&lt;p&gt;Another thing, courses tend to get outdated easily especially when technologies grow at a really, really quick pace. &lt;/p&gt;

&lt;p&gt;One day EC2 instances are limited to 20 instances per region, the next day its now based on number of vCPUs. Today you have a Zookeeper that handles all the syncing stuff, tomorrow it's removed entirely. Some changes may be small and some changes may be just a button moved in the UI, but add it up to all the other stuff that you're working on and they start to become significant.&lt;/p&gt;

&lt;p&gt;One day you have weeks to play around on this fascinating new tech you just discovered, tomorrow you just have two weeks to explore it and come up with a bare minimum, usable solution.&lt;/p&gt;

&lt;p&gt;I guess my point is, it took me almost 4 years (even now I'm still trying) to shift from a structured, college-tailored type of kind learning to the actual industry-setup of acquiring knowledge. I'm calling the college-type courses kind because you have a clear outline of what you need to follow, starting from the baby steps of firing up your first terminal, to eventually going through harder and more difficult stuff. You have a clear picture of what the problem is and what you need to accomplish first.&lt;/p&gt;

&lt;p&gt;On the other hand, the actual industry doesn't lay out all the variables you need. It just presents a list of requirements, and it's up to you figure out what tools you need to use. It doesn't even give you a real problem, and it's up to you to come up with the questions and eventually, with the answers.&lt;/p&gt;

&lt;p&gt;I guess this is what you might call ill-defined problems, where an almost perfect and unique solution oftentimes doesn't exist. During my stint at my previous job and in my current job, I've learned so much about how solutions are pieced together. You might have vendor's assistance or external professional services helping you out, but you'll come to realize that solving problems are not as straightforward as they seem. Some tasks need to be prioritized over others and some pressure from the business side may arise midway the sprint, which then prompts you to re-think which of the questions you have on your plate needs to be answered first.&lt;/p&gt;

&lt;p&gt;So, the industry's way of learning tend to be a bit messy. You search what you need at the moment and you try it immediately on your test environment to see if it works. If it does, you try to incorporate piece-by-piece to your code. If it doesn't cause too much noise in the logs, if it passed all the unit tests, OAT, and such, and ultimately if everything seems to work smoothly, it might just find its way into production. But wait, here's the catch: you need to have all of it done in four sprints or less. &lt;/p&gt;

&lt;p&gt;Now, this could introduce what you might call &lt;strong&gt;technical debt&lt;/strong&gt; which is incurred when you prioritized a quick delivery over a perfect code.&lt;/p&gt;

&lt;p&gt;Is this bad? Yes. No. I don't know. On one hand, you can't really perfect a code because it may depend on other factors that's out of your control such as the version of the platform you're running it on or the system updates that other teams are rolling out.&lt;/p&gt;

&lt;p&gt;On the other, the quicker something fails, the quicker you can correct it. So it's as if we're always looking for ways to break the system so we can optimize it quickly.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Wait. Where was I?&lt;/strong&gt;&lt;br&gt;
Oh, yes, a shift of thinking. I guess I've laid out my take on how "learning-on-the-job" differs so much with "learning-on-demand".&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So, should I stop taking courses and instead focus on projects and go straight to specifics?&lt;/strong&gt;&lt;br&gt;
If something's entirely new to you, you will need to build a solid foundation on it. That's what courses are for. They equip you with the basic tools that you (might) need to solve problems.&lt;/p&gt;

&lt;p&gt;Along the way, you get to use these tools to answer your own questions. Other times, situations may require you to drop these tools altogether to adapt other tools better suited for the challenge at hand.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I am still confused.&lt;/strong&gt;&lt;br&gt;
Well, you're not alone. I still haven't figured all of it out yet. I still have a ton of courses in my laptop which I've yet to take. And since time is a limited commodity, I developed a strategy on how I could learn things better and apply them.&lt;/p&gt;

&lt;p&gt;If my goal is to take a certification exam, I try to breeze through the course, do the labs, jot down notes, and prep up with some final practice tests. Once I passed the exam, I delete the course.&lt;/p&gt;

&lt;p&gt;Yes. No hesitations. I know I wouldn't come back to it anymore and if I try to implement it on a project I'm working on, I'll just do a quick Google search on any error that I might encounter. I also get to pick just the specifics.&lt;/p&gt;

&lt;p&gt;Just like when you're picking apples, you get the good ones and enjoy it later.&lt;/p&gt;

&lt;p&gt;Bottom line is, I've equipped myself (I really hope I did) with the fundamentals during the discovery and review stage using the course as a tool. For the application stage, it's time to make use of my own tool: my Google-fu.&lt;/p&gt;

&lt;p&gt;Currently, I'm prepping up to take RHCSA for next year. So by next year, I'm expecting to have any of the RHEL-related courses completely deleted from my hard drive. &lt;/p&gt;

&lt;p&gt;By doing this, I'm forcing myself to think on my own instead of following the same exact steps that the instructor did. If I want to recall how I did a lab, I check my notes.  If it's not on my notes, it's probably on Google.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Okay, I think I got it.&lt;/strong&gt;&lt;br&gt;
If you did, then you're already one step ahead of me and you did a great job. Again, I don't have all the answers yet, I don't even know what the specific questions are. But I do hope and expect to learn more as I go out and try new labs, fail on my code, tail the logs, test out solutions, and then document them. Along the way, I don't just learn. I solve problems.&lt;/p&gt;

&lt;p&gt;And that I think is the real shift of thinking:&lt;br&gt;
When you shift from being a learner to a problem-solver.&lt;/p&gt;

&lt;p&gt;And when you've solved enough problems, you next shift to a much higher form of learning: passing it onto others.&lt;/p&gt;

</description>
      <category>devjournal</category>
      <category>devops</category>
      <category>systems</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>Killing a defunct process</title>
      <dc:creator>Eden Jose</dc:creator>
      <pubDate>Wed, 17 Nov 2021 22:40:32 +0000</pubDate>
      <link>https://dev.to/jeden/killing-a-defunct-process-7od</link>
      <guid>https://dev.to/jeden/killing-a-defunct-process-7od</guid>
      <description>&lt;ul&gt;
&lt;li&gt;What happened:&lt;/li&gt;
&lt;li&gt;What this means&lt;/li&gt;
&lt;li&gt;What to do&lt;/li&gt;
&lt;li&gt;References&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Encountered this when I was trying to install htop on one of my test-RHEL EC2 instances. I was following the steps in this &lt;a href="https://www.cyberciti.biz/faq/how-to-install-htop-on-rhel-8-using-yum/"&gt;link.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I've also learned that defunct processes are almost similar with zombie processes, but there's also some differences which you can read &lt;a href="https://stackoverflow.com/questions/47977402/zombie-vs-defunct-processes"&gt;here.&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  What happened:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Two terminals opened, both connected to same instance&lt;/li&gt;
&lt;li&gt;installed the package on second terminal while update was running on first&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Got this message on second terminal when trying to install package and update simultaneously:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Running transaction check
Waiting &lt;span class="k"&gt;for &lt;/span&gt;process with pid 5941 to finish.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Checking which process is that&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;ps &lt;span class="nt"&gt;-ef&lt;/span&gt; |grep 5941
root        5941    5939 18 06:00 pts/0    00:01:42 yum update &lt;span class="nt"&gt;-y&lt;/span&gt;
root       36173   36153  0 06:09 pts/2    00:00:00 &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;--color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;auto 5941

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

&lt;/div&gt;



&lt;p&gt;Since it was taking some time, I had to cancel the update running on the first terminal so I can install some packages first and then run the update again.&lt;/p&gt;

&lt;p&gt;When I try install the packages again, it still returned same messaged about the same pid. Checking the processes again, it now showed "defunct"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;ps &lt;span class="nt"&gt;-ef&lt;/span&gt; |grep 5941
root        5941    5939 18 06:00 pts/0    00:01:42 &lt;span class="o"&gt;[&lt;/span&gt;yum] &amp;lt;defunct&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I tried killing by running &lt;code&gt;kill -9 5941&lt;/code&gt; but it still appear as a "defunct" process.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this means
&lt;/h2&gt;

&lt;p&gt;Based on one of the link I found online:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;From your output we see a "defunct", which means the process has either completed its task or has been corrupted or killed, but its child processes are still running or these parent process is monitoring its child process. To kill this kind of process, kill -9 PID doesn't work. You can try to kill them with this command but it will show this again and again.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What to do
&lt;/h2&gt;

&lt;p&gt;Determine which is the parent process of this defunct process and kill it. To know this run the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;ps &lt;span class="nt"&gt;-ef&lt;/span&gt;|grep defunct
UID          PID    PPID  C    
root        5941    5939  6 06:00 pts/0    00:01:42 &lt;span class="o"&gt;[&lt;/span&gt;yum] &amp;lt;defunct&amp;gt;
eden       36210    6097  0 06:24 pts/2    00:00:00 &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;--color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;auto defunct

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

&lt;/div&gt;



&lt;p&gt;Then run the sigkill cmmand again but this time include both the PID and PPID.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo kill&lt;/span&gt; &lt;span class="nt"&gt;-9&lt;/span&gt; 5941 5939
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo kill&lt;/span&gt; &lt;span class="nt"&gt;-9&lt;/span&gt; 36210 6097
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify the defunct process is gone by ps -ef | grep defunct&lt;/p&gt;




&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.cyberciti.biz/faq/how-to-install-htop-on-rhel-8-using-yum/"&gt;How to install htop on RHEL 8 using yum&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://askubuntu.com/questions/201303/what-is-a-defunct-process-and-why-doesnt-it-get-killed"&gt;What is a  process, and why doesn't it get killed?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/47977402/zombie-vs-defunct-processes"&gt;Zombie vs Defunct processes?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>devops</category>
      <category>dev</category>
    </item>
    <item>
      <title>Connecting via SSH from one EC2 instance to another</title>
      <dc:creator>Eden Jose</dc:creator>
      <pubDate>Wed, 17 Nov 2021 15:58:36 +0000</pubDate>
      <link>https://dev.to/jeden/connecting-via-ssh-from-one-ec2-instance-to-another-2mk1</link>
      <guid>https://dev.to/jeden/connecting-via-ssh-from-one-ec2-instance-to-another-2mk1</guid>
      <description>&lt;ul&gt;
&lt;li&gt;Pre-requisites&lt;/li&gt;
&lt;li&gt;Main Steps&lt;/li&gt;
&lt;li&gt;If something goes wrong&lt;/li&gt;
&lt;li&gt;References&lt;/li&gt;
&lt;li&gt;Final Reminders!&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;This is another quicknotes which I tend to forget at times. &lt;/p&gt;

&lt;h3&gt;
  
  
  Pre-requisites
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;two or more Amazon EC2 instances&lt;/li&gt;
&lt;li&gt;instances must be in same subnet and same availability zone&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Main Steps
&lt;/h3&gt;

&lt;p&gt;It actually only requires you to to generate an RSA key on each server. Assumption:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;server-a is source (my server-a is RHEL)&lt;/li&gt;
&lt;li&gt;server-b is destination (my server-b is Ubuntu)&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;On server-a, generate an rsa key by running:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh-keygen &lt;span class="nt"&gt;-t&lt;/span&gt; rsa
&lt;span class="c"&gt;# You would need to enter a passphrase twice - recommended to have a passphrase&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;On you &lt;code&gt;~/.ssh &lt;/code&gt; folder, you should now see two &lt;strong&gt;id_rsa&lt;/strong&gt;. 
One is a private key (something that's yours only) and a publc key(something you share). Note that you can rename your private and public key. Open the &lt;strong&gt;id_rsa.pub&lt;/strong&gt; using vi editor and copy the contents. W
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;[&lt;/span&gt;eden@tst-rhel ~]&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; .ssh/
&lt;span class="o"&gt;[&lt;/span&gt;eden@tst-rhel .ssh]&lt;span class="nv"&gt;$ &lt;/span&gt;ll
total 16
&lt;span class="nt"&gt;-rw-------&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt; 1 eden eden  799 Nov 17 22:03 authorized_keys
&lt;span class="nt"&gt;-rw-------&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt; 1 eden eden 2655 Nov 17 21:44 id_rsa-rhel
&lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt; 1 eden eden  567 Nov 17 21:44 id_rsa-rhel.pub
&lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt; 1 eden eden  523 Nov 17 21:57 known_hosts

&lt;span class="o"&gt;[&lt;/span&gt;eden@tst-rhel ~]&lt;span class="nv"&gt;$vi&lt;/span&gt; ~/.ssh/id_rsa.pub
ssh-rsa &lt;span class="k"&gt;************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************&lt;/span&gt;eden@tst-rhel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Now open another terminal and login to server-b. Go to the same &lt;code&gt;~/.ssh &lt;/code&gt; folder and open the &lt;strong&gt;authorized_keys&lt;/strong&gt; file. Append the previously copied public key(from server-a).
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;[&lt;/span&gt;eden@tst-ubuntu .ssh]&lt;span class="nv"&gt;$ &lt;/span&gt;vi authorized_keys

ssh-rsa &lt;span class="k"&gt;************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************&lt;/span&gt;qwerty-keypair

&lt;span class="c"&gt;# server-a public-key should be appended below.&lt;/span&gt;
ssh-rsa &lt;span class="k"&gt;************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************&lt;/span&gt;eden@tst-rhel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Trust should always be two-way. On server-b, generate the rsa keys (step 1), copy the public key (step 2), and then go back to server-a to append server-b's public key to the authorized_keys file (step 3).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;From server-a, try to SSH to server-b.&lt;br&gt;
From server-b, try to SSH to server-a.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  If something goes wrong
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Confirm that the IP you're using on the SSH command is still valid. The EC2 instances' public IP changes when stopped and started unless the instances are using Elastic IPs.&lt;/li&gt;
&lt;li&gt;Check NACLs are set to default - they're normally unchanged&lt;/li&gt;
&lt;li&gt;Ensure that they're on the same security group&lt;/li&gt;
&lt;li&gt;Ensure that SSH through port 22 is allowed in the &lt;strong&gt;Inbound Rules&lt;/strong&gt; section of the security group.&lt;/li&gt;
&lt;li&gt;Try creating another destination EC2 instance in the same public subnet/Availability zone&lt;/li&gt;
&lt;li&gt;You may also create another VPC and instances inside that VPC&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;p&gt;These are some links that I find to be useful. You may find some others&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/55212032/cant-ssh-into-aws-ec2-instance"&gt;Can't SSH into AWS EC2 instance&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://superuser.com/questions/1135766/how-to-ssh-from-one-ec2-instance-to-another"&gt;How to ssh from one ec2 instance to another?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://phoenixnap.com/kb/ssh-to-connect-to-remote-server-linux-or-windows"&gt;How to Use SSH to Connect to a Remote Server in Linux or Windows&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Final Reminders!
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Yes, even if you've done the steps a couple of times in the past, you might still forget how to do it. This is the why of this notes&lt;/li&gt;
&lt;li&gt;Having said, always good to document. &lt;/li&gt;
&lt;li&gt;Never ever share your Private key. That's yours and yours alone!&lt;/li&gt;
&lt;li&gt;It is recommended to use key-based authentication instead of password-based authentication&lt;/li&gt;
&lt;li&gt;You may try to search easier methods of connecting by using passwords but remember, passwords can be brute-forced!&lt;/li&gt;
&lt;li&gt;Lastly, enjoy!&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>devops</category>
      <category>devjournal</category>
      <category>linux</category>
      <category>bash</category>
    </item>
    <item>
      <title>Get Virtual! with Python Virtual Environments</title>
      <dc:creator>Eden Jose</dc:creator>
      <pubDate>Mon, 11 Oct 2021 16:41:23 +0000</pubDate>
      <link>https://dev.to/jeden/get-virtual-with-python-virtual-environments-4ci7</link>
      <guid>https://dev.to/jeden/get-virtual-with-python-virtual-environments-4ci7</guid>
      <description>&lt;p&gt;These are used to isolate environments and resolve &lt;em&gt;dependency conflict resolution&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;This ensure projects have isolated siloes where they live and have their own dependency tree that don't interfere with one another.&lt;/p&gt;

&lt;p&gt;Another thing, feel free to jump to sections that you're only interested in!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Python Dependencies&lt;/li&gt;
&lt;li&gt;Installing Libraries&lt;/li&gt;
&lt;li&gt;Using a requirements.txt&lt;/li&gt;
&lt;li&gt;Using env&lt;/li&gt;
&lt;li&gt;Using venv&lt;/li&gt;
&lt;li&gt;Using virtualenvwrapper&lt;/li&gt;
&lt;li&gt;
Errors

&lt;ul&gt;
&lt;li&gt;mkvirtualenv: command not found&lt;/li&gt;
&lt;li&gt;virtualenvwrapper Command '' not found, but can be installed with ...&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;References&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Python Dependencies
&lt;/h2&gt;

&lt;p&gt;You will often use 3rd-party libraries - non-default libraries which doesn't come along with Python.&lt;br&gt;
You'll have to import and install them before they can be used.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;normally installed using &lt;em&gt;pip&lt;/em&gt; or &lt;em&gt;easy_install&lt;/em&gt; &lt;/li&gt;
&lt;li&gt;libraries are pulled from the &lt;strong&gt;pupi.org&lt;/strong&gt; or &lt;strong&gt;Python Package Index&lt;/strong&gt; which as an enormous index of libraries&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CQ9Pdux5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oc61ua91jtrixty74j6h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CQ9Pdux5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oc61ua91jtrixty74j6h.png" alt="image"&gt;&lt;/a&gt; &lt;/p&gt;


&lt;h2&gt;
  
  
  Installing Libraries
&lt;/h2&gt;

&lt;p&gt;To install a library, as example, django&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;django
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To install a specific version of django,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;&lt;span class="nv"&gt;django&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;2.2.12
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To check the version of Django installed, you can run any of the commands below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;django &lt;span class="nt"&gt;--version&lt;/span&gt;
python &lt;span class="nt"&gt;-m&lt;/span&gt; django &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also view the versions of all installed packages, including Django,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip freeze
python &lt;span class="nt"&gt;-m&lt;/span&gt; pip freeze
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To save all of these data (versions of each modules) to be reused or processed later, you can forward them to a file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip freeze &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; module-versions.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To upgrade to a newer version&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--upgrade&lt;/span&gt; django
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To uninstall it, don't delete the folder, instead&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip uninstall django
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another example: installing the "site" library&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;import site
print&lt;span class="o"&gt;(&lt;/span&gt;site.getsitepackages&lt;span class="o"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Using a requirements.txt
&lt;/h2&gt;

&lt;p&gt;Another way to install multiple third parties with just a single command is to put them into a single &lt;em&gt;requirements.txt&lt;/em&gt; file and use &lt;em&gt;pip&lt;/em&gt; to to do a bulk-install.&lt;/p&gt;

&lt;p&gt;(Note that it's recommended to install modules for a project in a virtual environment. Read below to learn more about this.)&lt;/p&gt;

&lt;p&gt;To install from a requirements file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Using env
&lt;/h2&gt;

&lt;p&gt;Let's take django as our example again. We recently installed django version 2.2.12. If we are to install a new version, v3.0, then it will override and uninstall the v2.2.12.&lt;/p&gt;

&lt;p&gt;Some projects need specific versions of a library and this is where virtual environments come into play. Virtual environments exist to isolate projects and their dependencies from one another.&lt;/p&gt;

&lt;p&gt;To create a virtual environment, we can use venv&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python &lt;span class="nt"&gt;-m&lt;/span&gt; venv my-project-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After you run this, a folder for the virtual environment will be created.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;ll
total 0
drwxr-xr-x 1 Eden Jose 197610 0 Sep 14 12:16 my-project-1/

&lt;span class="nv"&gt;$ &lt;/span&gt;ll my-project-1/
total 5
drwxr-xr-x 1 Eden Jose 197610   0 Sep 14 12:16 Include/
drwxr-xr-x 1 Eden Jose 197610   0 Sep 14 12:16 Lib/
&lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt; 1 Eden Jose 197610 121 Sep 14 12:16 pyvenv.cfg
drwxr-xr-x 1 Eden Jose 197610   0 Sep 14 12:16 Scripts/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To activate a virtual environment, run the "activate" script inside the &lt;em&gt;Scripts&lt;/em&gt; folder of the project. As an example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;source&lt;/span&gt; ./my-project-1/Scripts/activate
&lt;span class="err"&gt;$&lt;/span&gt;
&lt;span class="o"&gt;(&lt;/span&gt;my-project-1&lt;span class="o"&gt;)&lt;/span&gt; 
Eden Jose@EdenJose MINGW64 ~/Desktop/Git/5-Virtual-Envs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that the name of the virtual environment can now be seen at the prompt. To exit out of the virtual environment, simply run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;deactivate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Using venv
&lt;/h2&gt;

&lt;p&gt;Another way to create virtual environments is through &lt;em&gt;virtual env&lt;/em&gt;.&lt;br&gt;
Note that virtual env doesn't ship alongside your Python installation. To install virtual env,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;virtualenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This take a similar step to create a new environment and activate it,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;virtualenv my-project-2

&lt;span class="c"&gt;# you can also use&lt;/span&gt;
python &lt;span class="nt"&gt;-m&lt;/span&gt; virtualenv my-project-2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can create the virtual environment with a different Python installation by using the "-p" flag&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Check the python installations you currently have&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;where python
C:&lt;span class="se"&gt;\U&lt;/span&gt;sers&lt;span class="se"&gt;\E&lt;/span&gt;den Jose&lt;span class="se"&gt;\A&lt;/span&gt;ppData&lt;span class="se"&gt;\L&lt;/span&gt;ocal&lt;span class="se"&gt;\P&lt;/span&gt;rograms&lt;span class="se"&gt;\P&lt;/span&gt;ython&lt;span class="se"&gt;\P&lt;/span&gt;ython39&lt;span class="se"&gt;\p&lt;/span&gt;ython.exe
C:&lt;span class="se"&gt;\U&lt;/span&gt;sers&lt;span class="se"&gt;\E&lt;/span&gt;den Jose&lt;span class="se"&gt;\A&lt;/span&gt;ppData&lt;span class="se"&gt;\L&lt;/span&gt;ocal&lt;span class="se"&gt;\P&lt;/span&gt;rograms&lt;span class="se"&gt;\P&lt;/span&gt;ython&lt;span class="se"&gt;\P&lt;/span&gt;ython38&lt;span class="se"&gt;\p&lt;/span&gt;ython.exe

&lt;span class="c"&gt;# You can choose from this two and create a virtual env with that version&lt;/span&gt;
python &lt;span class="nt"&gt;-m&lt;/span&gt; virtualenv &lt;span class="nt"&gt;-p&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Using virtualenvwrapper
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This is what I am using in labs and even at work. Treat this section as standalone, and can be setup even without the venv or env&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is another virtualenv library which wraps up some useful management functionality for virtualenv. One feature of this is it manages a single location of all your projects.&lt;/p&gt;

&lt;p&gt;Unlike virtualenv and env where the project folder is created on your current working directory, virtualenvwrapper creates a folder is the user's home directory.&lt;/p&gt;

&lt;p&gt;virtualenvwrapper maintains this folder where all your environment folders are created by default. You can setup your own directory where all the virtual environments folder will be created by creating the variable &lt;strong&gt;WORKON_HOME&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I had some problems when I was trying this one. As a solution, I just uninstalled any existing virtualenvwrapper installed on my system and do a fresh install. This&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To do a fresh install,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;joseeden@EdenJose:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;pip uninstall virtualenvwrapper
joseeden@EdenJose:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;virtualenvwrapper
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, append this to your &lt;strong&gt;.bashrc&lt;/strong&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
&lt;span class="c"&gt;# Change the WORKON_HOME path to your directory where you want all your virtual environment folders created&lt;/span&gt;
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;WORKON_HOME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'/mnt/c/Users/Eden Jose/Desktop/Git/5-Virtual-Envs'&lt;/span&gt;
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;VIRTUALENVWRAPPER_PYTHON&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'/usr/bin/python3'&lt;/span&gt;
&lt;span class="nb"&gt;source&lt;/span&gt; /usr/local/bin/virtualenvwrapper.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To create a virtual environment&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkvirtualenv &amp;lt;name&amp;gt;

&lt;span class="c"&gt;# Sample&lt;/span&gt;
joseeden@EdenJose:~&lt;span class="nv"&gt;$ &lt;/span&gt;mkvirtualenv project-a
created virtual environment CPython3.8.10.final.0-64 &lt;span class="k"&gt;in &lt;/span&gt;21319ms...
&lt;span class="o"&gt;(&lt;/span&gt;project-a&lt;span class="o"&gt;)&lt;/span&gt; joseeden@EdenJose:~&lt;span class="err"&gt;$&lt;/span&gt;

&lt;span class="c"&gt;# Note that to create another virtual envionment, exit out of the previous virtual environment by running "deactivate"&lt;/span&gt;

joseeden@EdenJose:~&lt;span class="nv"&gt;$ &lt;/span&gt;mkvirtualenv project-b
created virtual environment CPython3.8.10.final.0-64 &lt;span class="k"&gt;in &lt;/span&gt;21319ms...
&lt;span class="o"&gt;(&lt;/span&gt;project-b&lt;span class="o"&gt;)&lt;/span&gt; joseeden@EdenJose:~&lt;span class="err"&gt;$&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To see all your virtual environments,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;joseeden@EdenJose:~&lt;span class="nv"&gt;$ &lt;/span&gt;workon
project-a
project-b
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To switch between virtual environments, you can simply run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;joseeden@EdenJose:~&lt;span class="nv"&gt;$ &lt;/span&gt;workon project-b
&lt;span class="o"&gt;(&lt;/span&gt;project-b&lt;span class="o"&gt;)&lt;/span&gt; joseeden@EdenJose:~&lt;span class="err"&gt;$&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To exit out of a virtual environment&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;(&lt;/span&gt;project-b&lt;span class="o"&gt;)&lt;/span&gt; joseeden@EdenJose:~&lt;span class="nv"&gt;$ &lt;/span&gt;deactivate
joseeden@EdenJose:~&lt;span class="err"&gt;$&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  ERRORS
&lt;/h2&gt;

&lt;h3&gt;
  
  
  mkvirtualenv: command not found
&lt;/h3&gt;

&lt;p&gt;If you get an error "command not found", this might mean virtualenvwrapper was not properly installed. &lt;/p&gt;

&lt;p&gt;You can simply re-do the installation.&lt;br&gt;
I had issues also when trying the virtualenvwrapper on Git Bash in VSCode so I decided to run the commands below in WSL.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;pip uninstall virtualenv &lt;span class="nt"&gt;-y&lt;/span&gt; 
&lt;span class="nb"&gt;sudo &lt;/span&gt;pip uninstall virtualenvwrapper &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;virtualenv
&lt;span class="nb"&gt;sudo &lt;/span&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;virtualenvwrapper
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"WORKON_HOME='/mnt/c/Users/Eden Jose/Desktop/Git/5-Virtual-Envs'"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; ~/.bashrc
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"source &lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;which virtualenvwrapper.sh&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; ~/.bashrc
&lt;span class="nb"&gt;.&lt;/span&gt; ~/.bashrc

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

&lt;/div&gt;






&lt;h3&gt;
  
  
  virtualenvwrapper Command '' not found, but can be installed with ...
&lt;/h3&gt;

&lt;p&gt;When you create a virtual environment using the &lt;em&gt;mkvirtualenv&lt;/em&gt; command, you might see this error message&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;joseeden@EdenJose:/mnt/c/Users/Eden Jose&lt;span class="nv"&gt;$ &lt;/span&gt;mkvirtualenv project-a

Command &lt;span class="s1"&gt;''&lt;/span&gt; not found, but can be installed with:

&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;mailutils-mh  &lt;span class="c"&gt;# version 1:3.7-2.1, or&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;meshio-tools  &lt;span class="c"&gt;# version 4.0.4-1&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;mmh           &lt;span class="c"&gt;# version 0.4-2&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;nmh           &lt;span class="c"&gt;# version 1.7.1-6&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;termtris      &lt;span class="c"&gt;# version 1.3-1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To resolve this, add the lins below (in this order) to your &lt;strong&gt;.bashrc&lt;/strong&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;VIRTUALENVWRAPPER_PYTHON&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'/usr/bin/python3'&lt;/span&gt;
&lt;span class="nb"&gt;source&lt;/span&gt; /usr/local/bin/virtualenvwrapper.sh

&lt;span class="c"&gt;## Note that the path depends on where your Python is installed. To check&lt;/span&gt;
which python
which python3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/12647266/where-is-virtualenvwrapper-sh-after-pip-install"&gt;Where is virtualenvwrapper.sh after pip install?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.cbtnuggets.com/it-training/skills/python-virtual-environments"&gt;Python Virtual Environments&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>linux</category>
      <category>python</category>
      <category>devops</category>
      <category>devjournal</category>
    </item>
    <item>
      <title>Kept running "source .bashrc" every time I open WSL</title>
      <dc:creator>Eden Jose</dc:creator>
      <pubDate>Mon, 11 Oct 2021 14:51:22 +0000</pubDate>
      <link>https://dev.to/jeden/kept-running-source-bashrc-every-time-i-open-wsl-43bm</link>
      <guid>https://dev.to/jeden/kept-running-source-bashrc-every-time-i-open-wsl-43bm</guid>
      <description>&lt;p&gt;I was playing around and testing some stuff in Linux when i suddenly did a tweak which changed how my WSL terminal opens up. This is what my terminal looks like - notice it doesn't the distinct green + blue colors.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqapwn98ag3dpjgmd9gaf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqapwn98ag3dpjgmd9gaf.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After some searching I found two articles (links at the bottom) which describes the "sequence" which Unix follows when reading files. As summary, here's the files (in order):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;/etc/profile&lt;/li&gt;
&lt;li&gt;~/.bash_profile&lt;/li&gt;
&lt;li&gt;~/.bash_login
4 ~/.profile&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I added the function for .bashrc at the top of the &lt;strong&gt;.bash_profile&lt;/strong&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="c"&gt;## Loads .bashrc&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; ~/.bashrc &lt;span class="o"&gt;]]&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
        &lt;span class="nb"&gt;.&lt;/span&gt; ~/.bashrc
&lt;span class="k"&gt;fi&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Closed terminal and reopened it &lt;br&gt;
Voila! It now shows the green and blue colors.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3a4vvlafznzvn2wdm4pz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3a4vvlafznzvn2wdm4pz.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Adding this great explanation from the reference link:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;By default, Terminal starts the shell via /usr/bin/login, which makes the shell a login shell. On every platform (not just Mac OS X) bash does not use .bashrc for login shells (only /etc/profile and the first of .bash_profile, .bash_login, .profile that exists and is readable). This is why "put source ~/.bashrc in your .bash_profile" is standard advice&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://apple.stackexchange.com/questions/12993/why-doesnt-bashrc-run-automatically#comment13715_13019" rel="noopener noreferrer"&gt;Why doesn't .bashrc run automatically?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://hayne.net/MacDev/Notes/unixFAQ.html#shellStartup" rel="noopener noreferrer"&gt;How do I set up my shell execution PATH?
&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@kingnand.90/what-is-the-difference-between-bash-profile-and-bashrc-d4c902ac7308" rel="noopener noreferrer"&gt;What is the difference between .bash_profile and .bashrc?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>devops</category>
      <category>linux</category>
      <category>devjournal</category>
    </item>
  </channel>
</rss>
