Connect to Your Database Using an SSH Tunnel

Setting up an SSH tunnel allows you to use applications and tools on your local development machine while being connected to the remote server hosting your database. Because SSH uses an encrypted connection, data is protected over the wire.

1. On your local machine, type the following on the command line:

ssh -L [unused local port]:db-host-address:[remote database service port] [app server ssh username]@[app server host name]

Example for PostgreSQL:

ssh -L

2. You can confirm the tunnel is now open by examining your running processes:

ps aux | grep ssh

(You should see an entry that matches the command from step 1)

Configure Desktop Applications

If you are using a database editor or similar, use the following values after your tunnel is created:

  • Host: localhost
  • Port: 5555 (should match port you specified above)
  • Database Name
  • Database Username
  • Database Password

Terminating the Tunnel

Close your SSH tunnel when not using it to free up server resources.

Identify the process id from the ps aux command and type:

kill -9 (process id)

Additional Resources