How can I keep my SSH connection to a bastion host alive while accessing an RDS in a private subnet?
Asked by
CuriousCoder92
I'm currently using a bastion host, which is an EC2 instance, to connect to an RDS instance situated in a private VPC for development work. Here's how my setup looks: I have the RDS in a private subnet that isn't publicly accessible, while the bastion host is hosted in a public subnet. I connect to the RDS through the bastion using an SSH tunnel from my local machine. However, I've been facing an issue where my SSH connection to the bastion often disconnects after a short period. I've already attempted to add SSH configurations both locally and on the EC2 instance, like ServerAliveInterval set to 60 and enabling TCPKeepAlive, but the connection still drops. My goal is to keep the SSH tunnel alive continuously until I decide to disconnect. I'm curious if there are more reliable ways to maintain the SSH connection to the bastion, what the standard practices are for connecting to a private RDS from a local machine, and what methods others use in their organizations. Any best practices or setup examples would be greatly appreciated!
Answers
Have you considered implementing Cloudflare Zero Trust Network Access? By running the Zero Trust Tunnel application on your SSH bastion or even within your private subnet, you can maintain a reliable connection to your private resources. This method might be a bit more complex, but it can effectively solve your connectivity issues.
Reply to this answer
A solid approach is to look into using AWS Session Manager. It provides a more stable connection and can help prevent timeouts. If you think your SSH connection is timing out, make sure your settings are correct across all configurations. For instance, consider checking the ClientAliveInterval setting on your bastion host, alongside your current SSH configurations. Ultimately, I recommend using Session Manager for a more durable solution!
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions