Practical implementation of bastion hosts

Let's see how we implement it with the Terminal. We have three servers for a demo purpose:

  • Workstation: This is my laptop, which holds the private key
  • Bastion server: mydreams will be our bastion server
  • Remote server: mylife will be our remote server

Prerequisite: It is assumed that the public key of the user is added to the authorized_keys in both bastion as well as the remote server:

  1. Verify the contents of SSH agent:

This is my workstation (laptop) from which I will log in to bastion with SSH agent forwarding. If we see the current content of ssh-agent, my private key is already associated with the agent:

  1. Log in to the bastion server:

We now log in to the bastion server. Notice the –A option that stands for agent forwarding:

  1. Check if the agent has been forwarded:

If we run the ssh-add –l command on the bastion server, you will notice that the output will be similar to that of your workstation:

  1. Log in to the remote server:

Now, if we log in to the remote server, you will notice that it will log you in directly: