Step 1: Create a Bastion Host (also known as jump server) in a public subnet and Database server in a private subnet. Do SSH into the Bastion host.
![](https://pushpjeet.com/wp-content/uploads/2023/05/1-1024x513.png)
Step2: Load the key: To connect with the private (database) Server, we need the key to be present in the bastion host. For the same, we will create the private key in Bastion host.
![](https://pushpjeet.com/wp-content/uploads/2023/05/2-1024x547.png)
Linux Commands:
Connect as a root user:
Sudo su
Create a file with the same name as your key for private(databse)server:
# touch <privatekeyname.pem>
Open the newly created key with vim editor:
#vi <privatekeyname.pem>
Copy paste the text from your original key to this new key:
Paste, save and exit: press Escape then :wq
This will save the text and you will be exit from the editor.
Step3: Change the access permissions for the newly created key
![](https://pushpjeet.com/wp-content/uploads/2023/05/3-1024x522.png)
Linux Commands:
#chmod 400 <privatekeyname.pem>
Chmod is used to change the permissions of the file.
Step 4: SSH into the database server.
![](https://pushpjeet.com/wp-content/uploads/2023/05/4-1024x522.png)
Linux Command:
#ssh -i “newprivate.pem” ec2-user@10.0.23.80
Newprivate.pem is the newly created key.
Ec2-user is the username to connect
10.0.23.80 is the private IP of the database server.
Final Connection:
![](https://pushpjeet.com/wp-content/uploads/2023/05/5-1024x522.png)
Thus SSH successfully into the database server from the Bastion host.
** Pinging any website will not work as the database server is not connected to the internet.
Click to download pdf.