# SSH, SFTP, and databases behind NAT

Source: https://prontaro.com/docs/tunnels/ssh-and-db/

SSH into a server behind NAT, share an internal database with your team, or transfer files to an IP-allowlisted partner SFTP server — without setting up a VPN or opening router ports.

Prontaro splits inbound and outbound TCP into two dedicated commands: [`prontaro tcp`](https://prontaro.com/docs/tunnels/tcp.md) accepts incoming connections to your machine, while [`prontaro forward`](https://prontaro.com/docs/outbound/forward.md) routes your outbound connections from your dedicated static IPv4.

## Which command to choose

| Goal | Command | Minimum plan |
| --- | --- | --- |
| Connect via SSH, SFTP, or `psql` to your machine behind NAT | `prontaro tcp` | Tunnels (persistent port on shared IP) or Dedicated/Pro (port on your own IP) |
| Connect to an IP-allowlisted partner SFTP, SSH, or DB | `prontaro forward` | Dedicated or Pro (dedicated IPv4) |

In both modes Prontaro forwards TCP traffic directly without decryption — end-to-end SSH and database TLS encryption stay intact between client and server.

## Scenario 1. Inbound SSH and internal databases behind NAT (`prontaro tcp`)

`prontaro tcp` maintains an outbound TLS connection from your machine to a Prontaro node and exposes a port either on the shared Prontaro address (`<entry>.tcp.prontaro.run:41283`) or directly on your dedicated IP (`<your-IP>:22`, `<your-IP>:5432`).

Every new TCP tunnel starts closed to everyone. Packets from unlisted IPs are dropped by the node’s kernel filter before the TCP handshake completes and never count toward your monthly traffic allowance.

### Step 1. Start the TCP tunnel on the target machine

Expose port `22` on your dedicated IPv4 (or pass `--to shared` on Tunnels for a fixed port on the shared address):

```
 prontaro tcp 22 --name office-ssh --to 203.0.113.10
  Tunnel     office-ssh                              ● connected
  Address    203.0.113.10:22  →  127.0.0.1:22
  Access     closed   (as of launch)
  Server     <server> · <region> · 18 ms
```

The same pattern works for internal databases or another host on your LAN:

```bash
# Local PostgreSQL on port 5432 of your dedicated IP
prontaro tcp 5432 --name office-pg --to 203.0.113.10

# SSH to another LAN machine (10.0.0.15:22), published on port 2222
prontaro tcp 10.0.0.15:22 --name lan-ssh --to 203.0.113.10:2222
```

### Step 2. Allow only trusted IPs

In an interactive terminal, the CLI prompts to open the port for your current IP right away. You can update the allowlist at any time from the CLI or dashboard:

#### In the dashboard

1. Open **Tunnels**, select `office-ssh`, and switch to the **Access** tab.
2. Add the allowed IPv4 addresses or CIDRs and click **Save**.

Tunnels Access [Open in dashboard](https://my.prontaro.com/tunnels)

#### In the terminal (CLI)

```bash
# Open the port for a single public IPv4 address
prontaro access office-ssh allow 198.51.100.7

# Or for a static office CIDR
prontaro access office-ssh allow 198.51.100.0/24

# Close the port immediately when you finish
prontaro access office-ssh close
```

### Step 3. Connect via SSH, SFTP, and `psql`

```bash
# On your dedicated IPv4
ssh admin@203.0.113.10
sftp admin@203.0.113.10

# On a shared TCP port (Tunnels plan)
ssh -p 41283 admin@<entry>.tcp.prontaro.run

# To an internal PostgreSQL database
psql "postgresql://app@203.0.113.10:5432/prod?sslmode=require"
```

### Step 4. Run the tunnel as a system service

Install the tunnel as a background service (`systemd` on Linux or `launchd` on macOS) so it comes back automatically after reboots:

```bash
prontaro service install -- tcp 22 --name office-ssh --to 203.0.113.10
```

> **Do not enable --proxy-protocol for sshd or PostgreSQL**
>
> `--proxy-protocol v1|v2` prepends a HAProxy header to the TCP stream. Stock `sshd`, PostgreSQL, and MySQL do not expect that header and immediately drop the connection. Only enable `--proxy-protocol` in front of servers configured to parse it (nginx `stream`, HAProxy, Envoy).

For SSH access, also disable password logins in `/etc/ssh/sshd_config` (`PasswordAuthentication no`, SSH keys only) and keep the IP allowlist as narrow as possible.

## Scenario 2. Outbound SFTP, SSH, and database connections to an IP-allowlisted partner (`prontaro forward`)

When a partner SFTP server, bastion host, or cloud database only accepts connections from your static IP (`/32`) and you are connecting from a laptop, dynamic-IP office, or CI runner, use `prontaro forward`.

It opens a local listener (on `127.0.0.1` by default) and forwards traffic over TLS (port `443`) to your Prontaro entry node, where the connection exits to the partner from your static IP.

### Step 1. Add your static IP to the partner allowlist

Give the partner your dedicated IPv4 (`/32`) from **IP addresses** in the dashboard.

### Step 2. Forward the partner port to `127.0.0.1`

```
 prontaro forward 2222 sftp.partner.example.com:22 --ip 203.0.113.10
prontaro forward 2222 sftp.partner.example.com:22
  127.0.0.1:2222  →  sftp.partner.example.com:22 from your IP 203.0.113.10
```

*(You can omit `--ip` if your account has a single dedicated IP.)*

### Step 3. Connect with `HostKeyAlias`

Pass `-o HostKeyAlias=sftp.partner.example.com` so OpenSSH records and verifies the partner’s real host key in `~/.ssh/known_hosts` instead of binding it to `127.0.0.1`:

```bash
sftp -P 2222 -o HostKeyAlias=sftp.partner.example.com partner-user@127.0.0.1
ssh  -p 2222 -o HostKeyAlias=sftp.partner.example.com partner-user@127.0.0.1
```

To skip repeating flags — and let `rsync`, `scp`, and SFTP clients work out of the box — add an entry to `~/.ssh/config`:

```sshconfig
Host partner-sftp
  HostName 127.0.0.1
  Port 2222
  User partner-user
  HostKeyAlias sftp.partner.example.com
  IdentityFile ~/.ssh/id_ed25519_partner
```

Then run `sftp partner-sftp` or `rsync -avz ./export/ partner-sftp:/incoming/`.

Remote databases behind an IP allowlist work the same way:

```bash
prontaro forward 15432 db.partner.example.com:5432 --ip 203.0.113.10
psql "postgresql://app@127.0.0.1:15432/prod?sslmode=require"
```

> **SOCKS5 proxy alternative without a local process**
>
> If you cannot run a local `prontaro forward` process, OpenSSH and SOCKS5-aware clients can connect directly via your proxy credentials (`socks5h://<login>:<pass>@<entry>.prontaro.io:1080`).
>
> For day-to-day work, `prontaro forward` is simpler because it encrypts the hop to the node over TLS `:443`, reconnects automatically, and works with any TCP tool.

## Limits and notes

- **TCP and IPv4 only.** UDP and IPv6 are not supported by `prontaro tcp` or `prontaro forward`.
- **Up to 100 TCP ports per dedicated IP.** Port `443` on a dedicated IP can serve either one TCP tunnel or HTTPS tunnels, not both at the same time.
- **Active sessions during failover.** A server reboot or outage with [BGP failover](https://prontaro.com/docs/outbound/failover.md) preserves your IP, but existing SSH and database TCP sessions drop and must reconnect to the standby node. Routine Prontaro server updates do not drop them.
- **Database TLS hostname check (`verify-full`).** When connecting to `127.0.0.1:15432` over `prontaro forward`, the certificate matches `db.partner.example.com`, not `127.0.0.1` — set the expected hostname in your driver.

## Common errors

| Symptom | Cause | Fix |
| --- | --- | --- |
| Connection to `prontaro tcp` times out | New TCP tunnels start closed to everyone by default. | Run `prontaro access <name> allow 198.51.100.7` (replace with the required IP or CIDR), or open access in the dashboard (**Tunnels → Access**). |
| `WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED` on `127.0.0.1` | Another SSH host previously used the same local forwarded port. | Always pass `-o HostKeyAlias=<real_host>` or configure `~/.ssh/config`. |
| SSH or DB connection drops immediately | Local service is not listening or `--proxy-protocol` is enabled. | Check the local listener (`ss -tlnp`) and remove `--proxy-protocol` for `sshd`/DBs. |
| `403 destination_denied` in `prontaro forward` | Destination belongs to a private range (RFC 1918, loopback) or uses a blocked mail port (`25`, `465`, `587`). | Point `forward` to a public partner IPv4/domain and allowed port. |

## Next steps

- [TCP tunnels](https://prontaro.com/docs/tunnels/tcp.md) — full reference for inbound TCP tunnels and ports.
- [Access control & firewalls](https://prontaro.com/docs/tunnels/access.md) — configure IP allowlists for TCP ports.
- [Local port forwarding (prontaro forward)](https://prontaro.com/docs/outbound/forward.md) — full reference for outbound port forwarding from a static IP.
- [Background services (Linux & macOS)](https://prontaro.com/docs/cli/service.md) — run tunnels as a system service with auto-start.
- [Security, TLS, and production checklist](https://prontaro.com/docs/outbound/security.md) — encryption best practices and production hardening.
