<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Chukwubuikejoseph on Medium]]></title>
        <description><![CDATA[Stories by Chukwubuikejoseph on Medium]]></description>
        <link>https://medium.com/@chukwubuikejoseph217?source=rss-3f10bb93500f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*BZuXANhO9S680iJY</url>
            <title>Stories by Chukwubuikejoseph on Medium</title>
            <link>https://medium.com/@chukwubuikejoseph217?source=rss-3f10bb93500f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 19:21:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chukwubuikejoseph217/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Bastion host what for]]></title>
            <link>https://medium.com/@chukwubuikejoseph217/bastion-host-what-for-b7d0c0690ad0?source=rss-3f10bb93500f------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7d0c0690ad0</guid>
            <dc:creator><![CDATA[Chukwubuikejoseph]]></dc:creator>
            <pubDate>Fri, 13 Nov 2026 17:22:46 GMT</pubDate>
            <atom:updated>2026-11-13T17:22:46.067Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>First, what is a Bastion Host?</strong><br>A bastion host (also called a jump box), according to Google, is a specially provisioned, hardened computer that acts as a secure, single entry point from a public network (like the internet) into a private internal network.</p><p>In my own words, it’s a server that acts as a reachable intermediary to your usually unreachable resources in private subnets.</p><p>I think this diagram I created will help you visualise it better.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*ZXiuHS4W8mSwEHvLI6gRLg.jpeg" /><figcaption><strong>bastion host</strong></figcaption></figure><p>Press enter or click to view image in full size</p><p>Showing the flow of traffic from the public internet to resources on AWS in Private and Public Subnets<br>Now, why would anyone want to set up a bastion host? You can probably guess already from the explanation of what a bastion host is but to make it clearer. A bastion host can be used:</p><p>i. To safely manage and troubleshoot servers or databases in a private network without exposing those internal systems directly to the public internet.</p><p>ii. To reduce attack surface. Your internal app servers and databases live in private subnets with no public IP addresses so instead of opening management ports (like SSH or RDP) to the entire internet, you only open them on the hardened bastion host.</p><p>iii. To enforce strict security controls, such as multi-factor authentication (MFA) or SSH key pairs, at the bastion level before any jump to an internal asset.</p><p>iv. To control the flow of traffic. Your internal private systems are configured to only accept management connections coming from the internal IP address of the bastion host.</p><p>v. To revoke or disable an employee or contractor’s access in one central spot rather than hunting down user accounts across dozens of internal servers.</p><p>For this tutorial, I will be showing and explaining to you how to set up a bastion host using a public EC2 instance while the resource we are trying to reach will be an EC2 instance in a private subnet on AWS.</p><p>To get started, go to your AWS console. The two services we will be using are VPC and EC2…VPC for configuring our network settings and EC2 for launching our two instances.</p><p>Here is an example of AWS VPC console;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*hp3Kficw97M4aTG-m1ovRQ.jpeg" /><figcaption>replica of a VPC CONSOLE</figcaption></figure><p>Press enter or click to view image in full size</p><p>Every AWS account comes with a default VPC,</p><p>Next up is creating my public &amp; private subnets.<br>For the public subnet, .</p><p>First thing to do is select under which VPC I intend to have this subnet. Of course, I am going with the default so I click on it.</p><p>Press enter or click to view image in full size</p><p>For the rest of the subnet settings, here are the values I specified;</p><p>Subnet name: my-public-subnet</p><p>Availability Zone: eu-west-1a cause I am using my eu-west-1 region (Ireland)</p><p>IPv4 VPC CIDR block: 172.31.0.0/16 (The default VPC CIDR block AWS assigned to me)</p><p>IPv4 subnet CIDR block: I specified 172.31.128.0/24</p><p>My Public subnet configurations<br>Rules for picking your subnet CIDR<br>1. They must fit inside the VPC: My subnets as seen must start with 172.31.. I cannot use 172.32. or 10.0.. since my VPC is 172.31.</p><p>2. AWS always takes 5 IP addresses from every subnet you create (the first four and the last one) for routing, DNS, and network management. Never create a tiny /28 subnet (16 IPs) for a workload that needs 14 IPs, because you’ll only get 11 usable ones! Since, besides, this is just a test project, I do not have to worry about limited IPs so much.</p><p>3. The smaller the number after the slash, the more IPs you get, and consequentially, the larger the number after the slash, the less number of IPs you get. I have a slash /24 here so I have 256 IPs…which is like a nice standard for a subnet size. Perfect for standard web apps, databases, and general use.</p><p>Note: I would typically go for 172.31.1.0 or 172.31.24.0 but my default VPC has subnets that have the CIDR already causing the error message , so that’s why I went far and picked 128 for my public subnet, and 129 for my private subnet.</p><p>Next thing to do is create my private subnet.<br>Creating a private subnet is a bit different from creating a public subnet because the main difference between a private and a public subnet is that a subnet becomes public if its route table has a rule sending traffic to the VPC’s IGW. A subnet is private if its route table does not point to the IGW.</p><p>Putting both subnets in your default VPC ensures they are in the same network boundary, because by default, AWS automatically routes local traffic between all subnets inside the same VPC. For a standard, simple project like this, a bastion host must be in the same VPC as the private resources to talk to them natively over their private IP addresses.</p><p>Note: In large corporate networks, resources can live in different VPCs, it is why we hear of extra configuration like VPC Peering or a Transit Gateway to connect VPCs.</p><p>I went with my default VPC as usual to ensure my private subnet is in the same VPC as my public subnet.</p><p>For the rest of the private subnet settings, here are the values I specified;</p><p>Subnet name: my-private-subnet</p><p>Availability Zone: eu-west-1b ( I could choose the exact same zone I picked for my public subnet (Europe (Ireland) / eu-west-1a) because keeping them in the same zone makes testing easier and avoids cross-AZ data transfer fees, but it’s usually good practice to use multi-AZs to ensure multiple points of failures (good in case a region fails)) so I went with eu-west-1b.</p><p>IPv4 VPC CIDR block: 172.31.0.0/16 (The default VPC CIDR block AWS assigned to me)</p><p>IPv4 subnet CIDR block: I specified 172.31.129.0/24</p><p>Private subnet configurations<br>Now that I have set up my private subnet, I will go to VPC, and find the resource map to see a preview of what my current flow is like, I have not done anything to configure the private subnet’s route tables yet so it shoould still be connected to my VPC’s IGW.</p><p>Press enter or click to view image in full size</p><p>VPC Resource Map<br>And so, it is still connected to the IGW.</p><p>By default, AWS automatically associates new subnets with the VPC’s Main Route Table which already points to the Internet Gateway. If you leave it like this, your private subnet won’t actually be private, it will have a direct path to the internet like mine above.</p><p>To fix this, I will create a brand new, isolated Route Table and assign it specifically to my-private-subnet.</p><p>Creating the Private Route Table and associating it with my private subnet<br>Now, in the left-hand menu of the AWS VPC Console, I clicked on Route tables, clicked on create route table, specified the name I want (my-private-rt), selected my default VPC again and clicked on create route table to launch my configurations.</p><p>Route table config<br>Right now, my route table is empty as it’s not hooked up to anything yet so I will connect it to my private subnet.<br>Click on subnet associations under the newly created route table, click the Edit subnet associations button, then find and check the box next to your private subnet. Mine is my-private-subnet (172.31.129.0/24), then click save associations.</p><p>Now, if you check the Routes tab for your route table, you will see only one rule:</p><p>This means that traffic can only move locally inside the VPC. Because there is no route pointing 0.0.0.0/0 to an Internet Gateway (igw-xxxxxx), no one from the internet can get in, and the private instances cannot get out. The only way to reach it is via my bastion host in the public subnet.</p><p>If you go back to your VPC’s resource map now, you’ll see the new route table is not connected to the IGW.</p><p>Press enter or click to view image in full size</p><p>Private subnet is now truly private.<br>Now that private network is securely isolated, the next move is to create security groups for my bastion host and private ec2 instance.</p><p>Creating my Security Group Rules<br>For this, go to EC2, in the menu, find security groups and click on Create Security Groups.</p><p>For your bastion host (public) sg configuration:</p><p>Inbound rule: Allow SSH on Port 22, source “My IP”, or you can run curl icanhazip.com from your PC’s terminal to get your IP address. This rule allows access exclusively to your network</p><p>I prefer the curl command command because I selected “My IP” and AWS extracted my public IP, but it changed while I was setting up.</p><p>For your outbound rules, you can leave as is;<br>Outbound rule: Allow All traffic on All ports to 0.0.0.0/0 (Anywhere).</p><p>Allows the bastion to send traffic out to your private server.</p><p>Public SG Config<br>Click Create security group and that’s done. Onto the Private sg’s configuration.</p><p>For your private sg configuration:</p><p>This SG shields your private/backend resources so never use an IP address or 0.0.0.0/0 here. Instead, you will reference the Bastion’s Security Group ID for your inbound traffic.</p><p>Inbound rule: Allow SSH access on Port 22 from your bastion hosts’s SG ID. This means that only EC2 instances attached to/wearing the bastion-sg badge are allowed to connect.</p><p>Write on medium <br>Outbound rule: Allow All traffic on All Ports to 0.0.0.0/0. This is the standard default rule here, it’s nothing to be worried about since your private subnet has no Internet Gateway route, it won’t hit the public internet.</p><p>Now, to the last phase.</p><p>Creating the Bastion Host and Private EC2 Instance<br>Creating my bastion host had three main steps</p><p>Configuring the name : my-public-instance<br>AMI: Ubuntu Server 24.04 LTS<br>Instance Type: T2.micro</p><p>Instance config<br>2. Creating the key pair. I am using separate keys for the Public and Private instances because it enforces strict isolation typically between our public front door and our private backend.</p><p>If a hacker somehow compromises my local laptop or manages to steal the public instance’s private key (my-public-kp.pem), they still cannot touch my private backend resources. By using two different keys, a breach at the public perimeter does not automatically grant a bad actor total keys-to-the-kingdom access to my sensitive app and database servers.</p><p>3. Network Settings</p><p>For this, click on edit</p><p>VPC: My default VPC<br>Subnet: My public subnet<br>Auto-assign public IP: Enable (or it won’t be reachable from the internet)<br>Firewall (security groups): Click Select existing group and select the public sg from the dropdown.</p><p>Done, now Create Instance.</p><p>Bastion Host/ Jump Box/ Public EC2 Instance<br>Creating my private EC2 Instance had three main steps too</p><p>Configuring the name : my-private-instance<br>AMI: Ubuntu Server 24.04 LTS<br>Instance Type: T2.micro</p><p>2. Creating the key pair.</p><p>Press enter or click to view image in full size</p><p>3. Network Settings</p><p>VPC: My default VPC<br>Subnet: My private subnet<br>Auto-assign public IP: Disable<br>Firewall (security groups): Click Select existing group and select the private sg from the dropdown.<br>Press enter or click to view image in full size</p><p>Done, now Create Instance</p><p>Now that the two instances have been created, the next step is to SSH into the Bastion Host and then use SSH Agent Forwarding to jump safely into the private server…the moment of truth!</p><p>To securely connect to your private server without uploading your private key (.pem file) to the public bastion host, you must use SSH Agent Forwarding. This process lets the bastion host temporarily borrow your local computer’s keys to authenticate the second jump.</p><p>CD into where your key pair files were downloaded.</p><p>Step 1: Start the SSH Agent and Add my Key; eval “$(ssh-agent -s)”<br>Step 2: Add my private key to the agent; ssh-add my-private-kp.pem<br>Step 3: Verify the key was added; ssh-add -l</p><p>SSH Into the Bastion Host (With Forwarding Enabled).</p><p>Now, connect to your Bastion Host using the -A flag, which tells SSH to forward your keys.</p><p>For me: ssh -A ubuntu@3.249.104.251</p><p>SSH into Bastion Host<br>Jump into the Private Server<br>Once you successfully log into the Bastion Host, your terminal prompt will change to show you are inside the bastion. From here, you can jump straight into the private server.</p><p>For me: ssh ubuntu@172.31.129.46</p><p>SSH into private instance<br>Great job!</p><p>This command lets you ssh into the private instance through the bastion host with just one prompt:</p><p>ssh -i my-public-kp.pem -J ubuntu@bastion_public_ip ubuntu@private_ec2_private_ip</p><p>For me: ssh -i my-public-kp.pem -J ubuntu@3.249.104.251 ubuntu@172.31.129.46</p><p>And it’d done! We’ve successfully set up a bastion host and used it to SSH into our private EC2 instance.</p><p>Please note that it’s good practice to delete resources once you’re done with labs and projects.</p><p>Cost Traps to note for this project<br>Even though this is a simple lab, AWS can quietly charge you if you leave resources running or use certain default features. Here is how to keep this project 100% free or extremely cheap:</p><p>For a simple test lab, do not create a NAT Gateway. If your private server needs a package or update (like nginx or running sudo apt update) , download it on your Bastion host first and securely copy it over, or destroy the lab immediately after testing.<br>When you are done testing your project for the day, don’t just walk away. Stop or Terminate your Bastion Host to release the public IP and halt charges.<br>Even on a free tier account, keeping both your Bastion and Private EC2 instances running 24/7 will quickly eat through your 750 monthly Free Tier hours if you use more than one running instance at a time, always stop your instances when you take a break from working, and terminate them entirely once your project is finished.<br>Free or Zero Impact on your bill resources for this project<br>VPC (Virtual Private Cloud): Creating a custom VPC or using the default VPC costs $0. AWS does not charge for the network container itself.<br>Subnets: Carving your VPC into public and private blocks (/24 blocks) is completely free, regardless of how many you create.<br>Route Tables: Creating and associating custom route tables (like my-private-rt) costs $0.<br>Internet Gateway (IGW): Attaching an IGW to your VPC to allow public traffic costs $0 to maintain. You only pay for data transferred out to the internet, which is negligible for a few terminal commands.<br>Security Groups: Creating firewall rules for your bastion and private servers costs $0. AWS allows you to create hundreds of security groups for free.<br>Micro Instances: Micro instances (like t2.micro or t3.micro, depending on your region) offer 750 free hours per month under the Free Tier.<br>EBS Storage: You get up to 30 GB of free SSD storage per month across your instances, which easily covers the default 8 GB root volumes used by your two EC2 servers.<br>Key Pairs (.pem files): Creating and utilizing SSH key pairs for secure authentication costs $0.<br>Note: While the servers and network are structurally free, the public IPv4 address assigned to your Bastion host is the only item that will incur a small charge. As of 2024, AWS charges $0.005 per hour for all public IPv4 addresses, even on the Free Tier. To keep this project truly free, make sure to Terminate your instances when you are done so that the public IP address is released back to AWS.</p><p>Common mistakes or troubleshooting errors you might face for this project<br>1. “Operation Timed Out” Error</p><p>• The Symptom: You run ssh -A ubuntu@&lt;Bastion-IP&gt;, and the terminal hangs forever before throwing a timeout error.<br>• The Cause: This is a firewall or routing issue. Either your public subnet is missing a route to the Internet Gateway (IGW), or your Bastion’s Security Group has the wrong inbound rule.<br>• The Fix: Check your Bastion’s Security Group. Ensure the inbound rule is set to Protocol: TCP and Port Range: 22. If you selected “My IP” as the source, your internet provider might have changed your IP address since you created it, this happened to me. Run curl icanhazip.com in your terminal to verify your current IP matches the rule.</p><p>2. “Unprotected Private Key File!” (Permissions 0644 are too open)</p><p>The Symptom: Your terminal throws a massive warning banner and refuses to let you add the .pem file to your ssh-agent. It happened to me here<br>Press enter or click to view image in full size</p><p>Sample error message<br>• The Cause: Linux and Mac SSH clients require your private key files to be hidden from other users on your machine. By default, downloaded files are too exposed.<br>• The Fix: Run chmod 400 your-key.pem in your local terminal. This locks the file down so only your user profile can read it, which satisfies the SSH security check.</p><p>3. “Permission Denied (publickey)” on the Second Jump</p><p>The Symptom: You successfully log into your Bastion Host, but when you type ssh ubuntu@&lt;Private-IP&gt; to jump to the private server, it rejects your connection.<br>• The Cause: The Bastion host doesn’t have your private key, and your local computer forgot to pass it along. This happens if you forgot to run ssh-add locally, or forgot the -A flag when connecting to the Bastion.<br>• The Fix: Log out of the Bastion. On your local machine, run ssh-add -l to ensure your key is active in your local memory. Then, make sure you reconnect using ssh -A ubuntu@&lt;Bastion-IP&gt;. The -A is what enables the magic of key forwarding!</p><p>A gentle reminder remember to always check your IP Before hoping into the private server to know wether it have changed</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7d0c0690ad0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>