

Now, when we try to do a SSH, we can directly use the IP address, since we're already connected to the EC2 user. So, this is how the basic concept really works here. So, whenever we try to log in with the associated private key, the login is successful. So essentially, since we have both the public and the private key generated, we have uploaded this public key in both the Bastion-server and the private-EC2. So, what this basically means is that, since we have added the public key in the authorised keys, it means that any client who is trying to connect to the EC2 instances with any one of the authorised keys(which is the public key, and the associated private key) would be allowed to make a connection. We'll add it as part of the authorised keys in both the Bastion as well as the private EC2 by running the follwing command in both Bastion as well as the private EC2. We can get the private key by running the following command in the remote-client. Let's go to the SSH directory and copy the public key displayed by the remote-client. And the same connection will also fail to the private EC2 instance because we have not entered the authorised keys yet. Now, at this stage, if we try and connect to the Bastion server, that connection should fail. SSH directory, we should see that we have a public and a private key. Let's first connect to the client machine and we'll run the ssh-keygen command to quickly create a private key. This private key will have access to Bastion server and will have access to the private EC2, as well. So first, let's create a new private key. Here, the main point to remember is for the client to connect to a private EC2 instance, the client needs to have access to both the Bastion server, as well as the private EC2 instance, for successful SSH authentication. Once all the 3 EC2 instances start running, let's connect with all three of them. Let's give them the names as remote-client, bastion-server and private-ec2 respectively. To try out how bastion host works, let's create 3 EC2 instances(t2.micro for demo purpose) and name them for our easy understanding. A Bastion host helps you comply with these regulations by providing secure access and monitoring of all connections.Ĭost-Effective: By using a Bastion host, you can reduce the number of public IP addresses you need, which can help reduce costs. It allows you to control who has access to your private network and provides an additional layer of security.Ĭompliance: Many compliance regulations require that access to sensitive data be restricted and monitored. There are several reasons why you might want to use a Bastion host in AWS:Ī Bastion host provides a secure way to access your private network by acting as a gateway. This helps prevent unauthorised access to your private network, as all traffic must pass through the Bastion host first. It is typically placed in a public subnet and is used to establish a secure connection to your private network from outside. It is also known as a Jump host, is a special kind of server that acts as a secure gateway to access other servers in a private network. To overcome this issue, AWS offers a solution called a Bastion host.


This is because servers in a private network don't have a public IP address, making it impossible to connect to them directly from the internet. When you have a group of servers in a private network, it can be challenging to access them from the internet.
