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.

If Your Database Server Is Directly Accessible With SSH

This scenario tends to apply to legacy environments not using our database-as-a-service plans.

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

ssh -fNg -L [unused local port]:localhost:[remote server database port] username@[remote server IP address]

Example for PostgreSQL:

ssh -fNg -L 5555:localhost:5432 myusername@subdomain.healthcareblocks.com

Note that port 5555 can be any value not currently being used by a local process on your machine.

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)

If Your Database Server Is Only Accessible from Your Application Server

This scenario is common when using our database-as-a-service plans.

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 5555:somename.db.healthcareblocks.com:5432 myusername@subdomain.healthcareblocks.com

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.

Just grab the process id from the ps aux command and type:

kill -9 (process id)

Additional Resources