Tutorials

Connecting to databases through SSH tunnels

Most production databases do not accept connections from the internet. An SSH tunnel through a bastion host (the one SSH server you can log in to that can reach the database) lets your database client connect as if the server were on your own computer. These tutorials cover the details that differ for each database.

Transputty is in development and has no public build yet (release status). The OpenSSH and PuTTY steps in these tutorials work today; the Transputty steps describe the current development build.

All three tutorials follow one pattern: run ssh -N -L LOCALPORT:DBHOST:DBPORT user@sshserver, then point the client at 127.0.0.1 and the local port. Each uses a local port that differs from the database's own (5433 for PostgreSQL, 3307 for MySQL, 11433 for SQL Server), so that a database installed on your own computer cannot get in the way.

If you have never made a tunnel, do your first SSH tunnel on Windows first. The PostgreSQL tutorial is the gentlest of the three.

Hankinsoft also makes SQLPro Studio, a database client for Mac, iOS and Windows. Like many database clients it has its own SSH tunnel option; a separate tunnel is still useful when several tools share one connection or the route needs jump hosts. Every tutorial here works with any client.