<?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: Baraa Mohamed</title>
    <description>The latest articles on DEV Community by Baraa Mohamed (@baraamohamed2311).</description>
    <link>https://dev.to/baraamohamed2311</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%2F2416916%2F45b57434-c688-46ed-af54-4f6607f5cd11.png</url>
      <title>DEV Community: Baraa Mohamed</title>
      <link>https://dev.to/baraamohamed2311</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/baraamohamed2311"/>
    <language>en</language>
    <item>
      <title>Rename Functions, Variables, or Any Text Across Multiple Files with One Command! 🔍🔄</title>
      <dc:creator>Baraa Mohamed</dc:creator>
      <pubDate>Tue, 10 Dec 2024 14:58:24 +0000</pubDate>
      <link>https://dev.to/baraamohamed2311/rename-functions-variables-or-text-across-multiple-files-with-one-command-3o5k</link>
      <guid>https://dev.to/baraamohamed2311/rename-functions-variables-or-text-across-multiple-files-with-one-command-3o5k</guid>
      <description>&lt;p&gt;I’ve come into situation before while I was building Employee Management System Full-stack website, Where I needed to change name of variable and some functions but the issue was that they are used in many files.&lt;/p&gt;

&lt;p&gt;For them being used in multiple files it wasn’t logically to manually detect them in each file and replace them.&lt;/p&gt;

&lt;p&gt;One solution I found is using Linux commands :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;find&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./node_modules&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;  &lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;prune&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;o&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;*.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;exec&lt;/span&gt; &lt;span class="nx"&gt;sed&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;s/old_text/new_text/g&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;find&lt;/code&gt; : is used to find certain files, here we use it to find all &lt;code&gt;.js&lt;/code&gt; files&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;\( \)&lt;/code&gt;&lt;/strong&gt; &lt;strong&gt;: the backslashes are used for Linux to execute what’s inside instead of giving an error&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-path&lt;/code&gt;&lt;/strong&gt; &lt;strong&gt;: To specify certain path which we will prune&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-prune&lt;/code&gt;&lt;/strong&gt; &lt;strong&gt;: To ignore certain paths from this command’s execution&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-o&lt;/code&gt; : Is or option so if left side is executed ( which is ignoring &lt;code&gt;“node_modules”&lt;/code&gt;&lt;/strong&gt; ) &lt;strong&gt;we skip executing rest of command after &lt;code&gt;-o&lt;/code&gt; .&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-name "*.js"&lt;/code&gt;&lt;/strong&gt; &lt;strong&gt;: to find any file that is &lt;code&gt;.js&lt;/code&gt; when it’s not &lt;code&gt;“node_modules”&lt;/code&gt;&lt;/strong&gt; &lt;strong&gt;folder&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-exec sed&lt;/code&gt;&lt;/strong&gt; &lt;strong&gt;: To execute replacing command which is sed.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-i&lt;/code&gt;&lt;/strong&gt; &lt;strong&gt;: to actually change text in file.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;{}&lt;/code&gt; is a placeholder for the file or directory name that the &lt;code&gt;find&lt;/code&gt; command matches.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;+&lt;/code&gt; : Called batch mode tells &lt;code&gt;find&lt;/code&gt; to pass multiple matched files to the command in batches instead of running the command once per file.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Usage Example
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;I have 2 &lt;code&gt;test.js&lt;/code&gt; files one of them is in&lt;/strong&gt; &lt;strong&gt;&lt;code&gt;“node_modules”&lt;/code&gt; folder, Both of them has text “baraa mohamed”.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So we execute following command.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;find&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./node_modules&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;  &lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;prune&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;o&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;*.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;exec&lt;/span&gt; &lt;span class="nx"&gt;sed&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;s/baraa/XBaraaX/g&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;After execution result of &lt;code&gt;test.js&lt;/code&gt; outside&lt;/strong&gt; &lt;strong&gt;&lt;code&gt;“node_modules”&lt;/code&gt; :&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;XBaraaX&lt;/span&gt; &lt;span class="nx"&gt;mohamed&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Also after executing we find &lt;code&gt;test.js&lt;/code&gt;&lt;/strong&gt; &lt;strong&gt;inside &lt;code&gt;“node_modules”&lt;/code&gt; :&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;baraa&lt;/span&gt; &lt;span class="nx"&gt;mohamed&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see it did not change as we pruned ( ignored ) the whole &lt;strong&gt;&lt;code&gt;“node_modules”&lt;/code&gt; directory.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;🤍 I'd love to connect with you on LinkedIn—let's grow our network and share ideas! &lt;a href="https://www.linkedin.com/in/baraa-mohamed-4b2034284?lipi=urn%3Ali%3Apage%3Ad_flagship3_profile_view_base_contact_details%3BAIVW4ELGQHSFtLJUIpn8Yg%3D%3D" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>linux</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>What is the difference between NAT Gateway &amp; Internet Gateway? 🤔</title>
      <dc:creator>Baraa Mohamed</dc:creator>
      <pubDate>Tue, 10 Dec 2024 08:00:38 +0000</pubDate>
      <link>https://dev.to/baraamohamed2311/what-is-the-difference-between-nat-gateway-internet-gateway-320l</link>
      <guid>https://dev.to/baraamohamed2311/what-is-the-difference-between-nat-gateway-internet-gateway-320l</guid>
      <description>&lt;p&gt;This is likely the first question that comes to mind when dealing with a &lt;strong&gt;VPC&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
Let’s use the architecture in the image to simplify things further. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fulsefb2o5ui868iyao6f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fulsefb2o5ui868iyao6f.png" alt="Image description" width="800" height="320"&gt;&lt;/a&gt; &lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;strong&gt;Internet Gateway&lt;/strong&gt;:
&lt;/h4&gt;

&lt;p&gt;The &lt;strong&gt;Internet Gateway&lt;/strong&gt; is essentially the gateway to the external world for your VPC.&lt;br&gt;&lt;br&gt;
Without it, you won’t be able to access any server you deploy in the VPC, nor will the servers be able to access the internet.&lt;/p&gt;

&lt;p&gt;Here’s what it allows you to do:&lt;/p&gt;

&lt;p&gt;✅ &lt;strong&gt;SSH into any public subnet's server&lt;/strong&gt;, but only if it has a public IP.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Download tools&lt;/strong&gt; you need onto that server by accessing outside internet.  &lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;strong&gt;NAT Gateway&lt;/strong&gt;:
&lt;/h4&gt;

&lt;p&gt;You could still ssh from your public subnet to the private subnet but what if you need that private subnet to access the outside world (internet)?&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;NAT Gateway&lt;/strong&gt; enables your &lt;strong&gt;private subnets&lt;/strong&gt; to access the internet, but nothing from the internet can directly access your private servers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;IMPORTANT NOTE :&lt;/strong&gt; NAT Gateway must be placed in public subnet itself for it to be able to access outside internet, because remember any thing inside private subnet can not access internet by default.&lt;/p&gt;

&lt;p&gt;Here’s why this is useful:&lt;/p&gt;

&lt;p&gt;✅ &lt;strong&gt;Increased security&lt;/strong&gt; ⬆️&lt;br&gt;&lt;br&gt;
✅ You can &lt;strong&gt;download tools&lt;/strong&gt; from the internet onto your server in the private subnet.  &lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;strong&gt;Accessing Your Private Server&lt;/strong&gt;:
&lt;/h4&gt;

&lt;p&gt;To access a private server in this setup, you’ll follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;SSH&lt;/strong&gt; into your server in the public subnet (referred to as &lt;strong&gt;"Bastion"&lt;/strong&gt; in the image).
&lt;/li&gt;
&lt;li&gt;From the Bastion server, &lt;strong&gt;SSH again&lt;/strong&gt; into your server in the private subnet (referred to as &lt;strong&gt;"Private App"&lt;/strong&gt;).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;🤍 I'd love to connect with you on LinkedIn—let's grow our network and share ideas! &lt;a href="https://www.linkedin.com/in/baraa-mohamed-4b2034284?lipi=urn%3Ali%3Apage%3Ad_flagship3_profile_view_base_contact_details%3BAIVW4ELGQHSFtLJUIpn8Yg%3D%3D" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>awschallenge</category>
      <category>awsbigdata</category>
      <category>cloud</category>
    </item>
    <item>
      <title>SSH Tunnel: Forwarding Traffic between hosts</title>
      <dc:creator>Baraa Mohamed</dc:creator>
      <pubDate>Tue, 26 Nov 2024 14:25:29 +0000</pubDate>
      <link>https://dev.to/baraamohamed2311/ssh-tunnel-forwarding-traffic-between-hosts-4id2</link>
      <guid>https://dev.to/baraamohamed2311/ssh-tunnel-forwarding-traffic-between-hosts-4id2</guid>
      <description>&lt;p&gt;In cloud environments, you might encounter scenarios where you need to forward traffic securely between hosts. SSH tunneling, also known as port forwarding, is a technique that allows you to create a secure communication tunnel between two hosts over specific ports.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is SSH Tunneling?
&lt;/h3&gt;

&lt;p&gt;SSH tunneling enables secure access to remote services that are not directly accessible. For instance, you can access a private service on a cloud server through a public host. This approach helps maintain security by keeping sensitive services private.&lt;/p&gt;




&lt;h3&gt;
  
  
  Example: Accessing Jenkins Dashboard on AWS
&lt;/h3&gt;

&lt;p&gt;Suppose you have Jenkins running on an EC2 instance in AWS, and you want to access its dashboard on port &lt;strong&gt;8080&lt;/strong&gt;. Using SSH tunneling, you can securely forward traffic from your local machine to the Jenkins instance.&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;Ensure the Jenkins EC2 instance allows &lt;strong&gt;TCP&lt;/strong&gt; traffic on port &lt;strong&gt;8080&lt;/strong&gt; and HTTP traffic in its security group.&lt;/li&gt;
&lt;li&gt;Have the access key for the Jenkins EC2 instance.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Command to Create the Tunnel:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &lt;span class="nt"&gt;-i&lt;/span&gt; &amp;lt;access-key&amp;gt; &lt;span class="nt"&gt;-L&lt;/span&gt; &amp;lt;your-host-port&amp;gt;:&amp;lt;Jenkins-ip&amp;gt;:&amp;lt;Jenkins-port&amp;gt; &amp;lt;public-Jenkins-instance&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="s2"&gt;"myKey.pem"&lt;/span&gt; &lt;span class="nt"&gt;-L&lt;/span&gt; 4040:localhost:8080 ubuntu@ec2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation of Flags:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;i&lt;/code&gt;: Includes the access key file required for authentication.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;L&lt;/code&gt;: Specifies the local port (&lt;code&gt;4040&lt;/code&gt;), remote host (&lt;code&gt;localhost&lt;/code&gt; or the private IP of Jenkins), and remote port (&lt;code&gt;8080&lt;/code&gt;) for the tunnel.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;localhost&lt;/code&gt;: Refers to the Jenkins instance. SSH forwards traffic to port 8080 on the Jenkins EC2 instance.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Accessing Jenkins Locally
&lt;/h3&gt;

&lt;p&gt;After running the command, open your browser and navigate to &lt;a href="http://localhost:4040" rel="noopener noreferrer"&gt;http://localhost:4040&lt;/a&gt;. You should see the Jenkins dashboard, as traffic on port 4040 of your machine is securely forwarded to port 8080 on the EC2 instance.&lt;/p&gt;




&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;By leveraging SSH tunneling, you can securely access remote services like Jenkins dashboards without exposing them to the public internet. This technique is versatile and applicable to many cloud-based workflows.&lt;/p&gt;

&lt;p&gt;🤍 I'd love to connect with you on LinkedIn—let's grow our network and share ideas! &lt;a href="https://www.linkedin.com/in/baraa-mohamed-4b2034284?lipi=urn%3Ali%3Apage%3Ad_flagship3_profile_view_base_contact_details%3BAIVW4ELGQHSFtLJUIpn8Yg%3D%3D" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>linux</category>
      <category>ubuntu</category>
      <category>aws</category>
    </item>
    <item>
      <title>SSH-Agent: Simplifying SSH Key Management</title>
      <dc:creator>Baraa Mohamed</dc:creator>
      <pubDate>Tue, 26 Nov 2024 14:24:22 +0000</pubDate>
      <link>https://dev.to/baraamohamed2311/ssh-agent-simplifying-ssh-key-management-3j2a</link>
      <guid>https://dev.to/baraamohamed2311/ssh-agent-simplifying-ssh-key-management-3j2a</guid>
      <description>&lt;p&gt;&lt;strong&gt;SSH-Agent&lt;/strong&gt; is one of the tools in the SSH suite that simplifies managing access keys for secure server connections.&lt;/p&gt;

&lt;p&gt;You can think of the SSH-Agent as a "bag" that holds your access keys, allowing you to access servers conveniently through other servers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Starting the SSH-Agent
&lt;/h3&gt;

&lt;p&gt;Begin by running the following command to start the SSH-Agent:&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;eval&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;ssh-agent &lt;span class="nt"&gt;-s&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This initializes the agent — think of it as "opening the bag."&lt;/p&gt;

&lt;h3&gt;
  
  
  Adding Access Keys
&lt;/h3&gt;

&lt;p&gt;Next, add your access keys to the agent. Each key represents a credential for accessing different servers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh-add &amp;lt;file1&amp;gt;
ssh-add &amp;lt;file2&amp;gt;
ssh-add &amp;lt;file3&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is like placing keys into your bag.&lt;/p&gt;

&lt;h3&gt;
  
  
  Connecting to Servers
&lt;/h3&gt;

&lt;p&gt;To connect to a server using a specific access key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &amp;lt;access-key1&amp;gt; &lt;span class="nt"&gt;-A&lt;/span&gt; &amp;lt;server1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;v&lt;/code&gt;: Verbose mode — displays loading steps in the terminal (optional).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;i&lt;/code&gt;: Specifies the access key file for authentication.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;A&lt;/code&gt;: Forwards the SSH-Agent, allowing access to additional servers without re-entering keys.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Accessing Additional Servers
&lt;/h3&gt;

&lt;p&gt;If you need to SSH from &lt;code&gt;server1&lt;/code&gt; to &lt;code&gt;server2&lt;/code&gt;, 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;ssh &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &amp;lt;access-key2&amp;gt; &amp;lt;server2&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the &lt;code&gt;-A&lt;/code&gt; flag only if you plan to SSH further from &lt;code&gt;server2&lt;/code&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  Best Practices
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;ssh-add&lt;/code&gt; to securely load private keys into the agent.&lt;/li&gt;
&lt;li&gt;Forward the SSH-Agent (&lt;code&gt;A&lt;/code&gt;) only when necessary to minimize security risks.&lt;/li&gt;
&lt;li&gt;Regularly clean up your agent by running &lt;code&gt;ssh-add -D&lt;/code&gt; to remove all keys after your session.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;By using SSH-Agent, you can simplify secure server access while reducing repetitive key management tasks.&lt;/p&gt;

&lt;p&gt;🤍 I'd love to connect with you on LinkedIn—let's grow our network and share ideas! &lt;a href="https://www.linkedin.com/in/baraa-mohamed-4b2034284?lipi=urn%3Ali%3Apage%3Ad_flagship3_profile_view_base_contact_details%3BAIVW4ELGQHSFtLJUIpn8Yg%3D%3D" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>linux</category>
      <category>ubuntu</category>
      <category>aws</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Accessing EC2 In Private Subnet | Bastion | VPC | AWS</title>
      <dc:creator>Baraa Mohamed</dc:creator>
      <pubDate>Tue, 26 Nov 2024 14:20:55 +0000</pubDate>
      <link>https://dev.to/baraamohamed2311/methods-of-accessing-ec2-in-private-subnet-1gn0</link>
      <guid>https://dev.to/baraamohamed2311/methods-of-accessing-ec2-in-private-subnet-1gn0</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.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%2F1m0hcygkpjgdr295pun6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F1m0hcygkpjgdr295pun6.png" alt="Bastion - VPC - AWS - Archeticture" width="800" height="353"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Accessing Private EC2 Instances in AWS: A Guide
&lt;/h2&gt;

&lt;p&gt;Cloud architectures commonly use public and private subnets to balance accessibility and security. Public subnets host resources like bastion hosts or load balancers, while private subnets house sensitive workloads such as application servers. This setup ensures a secure environment, as private EC2 instances are only accessible through specific configurations.&lt;/p&gt;

&lt;h3&gt;
  
  
  Two Approaches to Access Private EC2 Instances
&lt;/h3&gt;

&lt;p&gt;Depending on your requirements, you can access an EC2 instance in a private subnet through one of two methods: SSH access or traffic forwarding.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Method 1: SSH Access to a Private EC2&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This method is ideal for performing configurations or debugging directly on the private EC2 instance.&lt;/p&gt;

&lt;h3&gt;
  
  
  Steps:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Start the SSH-Agent to manage your private keys:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;ssh-agent &lt;span class="nt"&gt;-s&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add the private EC2 key to the agent:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh-add &amp;lt;file-key-of-private-app&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Connect to the bastion host in the public subnet, forwarding the SSH-Agent:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &amp;lt;file-key-of-bastion&amp;gt; &lt;span class="nt"&gt;-A&lt;/span&gt; &amp;lt;public-instance&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;From the bastion host, SSH into the private EC2:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &amp;lt;file-key-of-private-app&amp;gt; &amp;lt;private-instance&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By forwarding the agent (&lt;code&gt;-A&lt;/code&gt;), you securely authenticate to the private instance without transferring your private keys.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Method 2: Port Forwarding&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If you need to access a service (e.g., Jenkins) running on the private EC2, port forwarding allows you to securely forward traffic through the bastion host.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example: Forwarding Jenkins Dashboard
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Start the SSH-Agent and add the private key:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;ssh-agent &lt;span class="nt"&gt;-s&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
ssh-add &amp;lt;file-key-of-private-app&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Forward traffic from port 8080 on the private EC2 to port 4040 on your local machine:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &amp;lt;file-key-of-bastion&amp;gt; &lt;span class="nt"&gt;-A&lt;/span&gt; &lt;span class="nt"&gt;-L&lt;/span&gt; 4040:&amp;lt;ip-of-private-jenkins-ec2&amp;gt;:8080 &amp;lt;public-instance&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open &lt;a href="http://localhost:4040/" rel="noopener noreferrer"&gt;http://localhost:4040&lt;/a&gt; in your browser to access the Jenkins dashboard.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Note:
&lt;/h3&gt;

&lt;p&gt;To retrieve the Jenkins setup password, use:&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 cat&lt;/span&gt; /var/lib/jenkins/secrets/initialAdminPassword
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This approach avoids exposing Jenkins to the internet, improving security.&lt;/p&gt;




&lt;h3&gt;
  
  
  Best Practices
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use SSH-Agent to securely store keys during your session.&lt;/li&gt;
&lt;li&gt;Enable agent forwarding (&lt;code&gt;A&lt;/code&gt;) only when necessary to minimize security risks.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Clean up your SSH session by removing keys after use:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh-add &lt;span class="nt"&gt;-D&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

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

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;With these methods, you can securely access private EC2 instances while maintaining a robust and secure cloud architecture.&lt;/p&gt;

&lt;p&gt;🤍 I'd love to connect with you on LinkedIn—let's grow our network and share ideas! &lt;a href="https://www.linkedin.com/in/baraa-mohamed-4b2034284?lipi=urn%3Ali%3Apage%3Ad_flagship3_profile_view_base_contact_details%3BAIVW4ELGQHSFtLJUIpn8Yg%3D%3D" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>linux</category>
      <category>awschallenge</category>
      <category>cloud</category>
    </item>
  </channel>
</rss>
