Connect to PostgreSQL through an SSH tunnel
Reach a database that is only open to an SSH server, on Mac, iPhone and iPad.
An SSH tunnel lets Datark reach a database that is not open to the internet. Datark signs in to an SSH server you can reach, and that server connects to the database on your behalf. The same steps work for MySQL, MariaDB, MongoDB and Redis.
What you need
- The address and SSH sign-in of a server your device can reach, such as a bastion host. You sign in with a password or a private key.
- The database address as that SSH server sees it, and the database user and password. If PostgreSQL runs on the SSH server itself, the address is
localhost. If it runs on another machine in the same network, use its private host name or IP address.
On Mac
- Press Command-N to add a connection and choose PostgreSQL.
- Enter the database host, port, database, user and password. The host is the address the SSH server uses, not the address you can reach from your Mac.
- Turn on SSH Tunnel, then fill in SSH Host, SSH Port and SSH Username.
- Under Authentication, choose Password or SSH Key. For a key, import one, generate one, or pick a key file.
- Choose Test Connection. The first time Datark meets an SSH server, the test shows the server’s fingerprint and sends no credentials. Compare it with the one your administrator gives you, turn on Trust this host, and test again.
- Save the connection and connect.
On iPhone and iPad
- Add a connection and choose PostgreSQL. Enter the database host, port, database, user and password, using the address as the SSH server sees it.
- Turn on Use SSH tunnel and open Tunnel details.
- Enter the SSH host, port and username, then choose a password or a private key you have imported.
- Save the connection and connect.
iOS can close an SSH tunnel when Datark goes to the background. If a connection drops after you come back to the app, connect again.
If it does not connect
- “Connected to SSH host bastion.example.com, but it could not reach 10.0.0.5:5432” (with your own host names). The SSH sign-in worked, but the SSH server cannot reach the database at that address. Use the address as seen from the SSH server, and check that its firewall allows the database port.
- A host key changed. Datark refuses a server whose key no longer matches the one it saved, because that can mean someone is intercepting the connection. Confirm the new fingerprint with the server’s administrator before you replace the saved key.
- Authentication failed. Check the SSH username and the key or password separately from the database user and password. They are different sign-ins.
Other ways to use SSH
You can also open a shell on the server from the Terminal workspace, or forward a local port. Datark forwards listen on 127.0.0.1 only. See the SSH client page for what the terminal does and where iPhone and iPad differ.
Download Datark. It's free.
Free for Mac, iPhone and iPad. No account required.