Deploying PostgreSQL on an Ubuntu or Debian Linux VPS (DigitalOcean Droplet, Linode, AWS EC2, or Hetzner) is one of the most common setups for web backends.

However, out-of-the-box, PostgreSQL on Linux is tightly locked down:

  1. It only listens on localhost (listen_addresses = 'localhost').
  2. Its client authentication configuration file (pg_hba.conf) rejects connections from external IP addresses.

Rather than modifying postgresql.conf and pg_hba.conf to expose your database port to the public internet, the secure, industry-standard approach is connecting through an SSH Tunnel.

In this guide, we show you how to connect your Mac directly to PostgreSQL on your Linux VPS using SQLOZ.

SQLOZ Native SSH Tunneling Connection Settings


1. Why You Shouldn’t Open Port 5432 to the Public Internet

To allow direct public TCP connections, you would have to:

  • Edit /etc/postgresql/16/main/postgresql.conf and set listen_addresses = '*'.
  • Edit /etc/postgresql/16/main/pg_hba.conf and add host all all 0.0.0.0/0 scram-sha-256.
  • Open port 5432 in UFW (sudo ufw allow 5432/tcp).

The Danger: Port 5432 is constantly scanned by automated brute-force botnets. Any unpatched PostgreSQL vulnerability or weak password leaves your database vulnerable to total exfiltration or ransomware.


2. The Clean, Secure Solution: SSH Tunneling in SQLOZ

When you connect via an SSH Tunnel, traffic travels over your existing encrypted SSH port (22), and PostgreSQL perceives the connection as originating locally from 127.0.0.1. You don’t have to change a single line of PostgreSQL configuration!

Step 1: Configure PostgreSQL Credentials

  1. In SQLOZ, click New Connection ➔ PostgreSQL.
  2. Host: 127.0.0.1 (the VPS’s internal loopback).
  3. Port: 5432.
  4. User & Password: Your PostgreSQL credentials (e.g. postgres or application user).
  5. Database: Your target database name.

Step 2: Configure the SSH Tunnel Tab

  1. Switch to the SSH Tunnel tab and toggle Use SSH Tunnel ON.
  2. SSH Host: Your Linux VPS public IP address or domain.
  3. SSH Port: 22 (or custom SSH port).
  4. SSH User: root or your sudoer username.
  5. Authentication: Select SSH Key File and choose your private key (~/.ssh/id_ed25519 or ~/.ssh/id_rsa).

Step 3: Test and Connect

Click Test Connection. SQLOZ negotiates the encrypted SSH handshake, forwards the local socket, and mounts your remote PostgreSQL database instantly.


3. Benefits of Native macOS Management with SQLOZ

Once connected to your Linux VPS in SQLOZ:

  • Interactive Visual Query Builder: Design multi-table queries without writing raw SQL.
  • Schema Compare & Sync: Compare your remote production schema against your local development database.
  • Keychain Security: All SSH key passphrases and database passwords are encrypted inside the macOS Keychain.

Summary

Never expose PostgreSQL port 5432 to public traffic.

By leveraging SQLOZ’s native SSH tunnel integration, you can manage PostgreSQL on any Linux VPS with maximum security and Apple Silicon performance.

Download SQLOZ for macOS and connect to your Linux VPS databases in seconds.