> ## Documentation Index
> Fetch the complete documentation index at: https://midplane.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# SSH bastions

> Reach a database on a private network through an SSH bastion: the key Midplane makes for each source, the restricted line to add to the bastion, and its pinned host key.

When your database isn't reachable from the internet, Midplane can reach it
through an SSH bastion: a server it can reach on its SSH port that can
reach the database. Midplane makes a key for the source; you add its public
half to the bastion, limited to forwarding to that one database.

## What you need

* A bastion running OpenSSH 7.2 or later, with TCP forwarding allowed
  (`AllowTcpForwarding`, on by default), whose SSH port accepts your
  region's [egress addresses](https://midplane.ai/docs/connect/allowlist.md). The database needs no
  rule for Midplane: it sees the bastion.
* A user on it for Midplane, such as `midplane`, with no password and best
  no login shell (`/usr/sbin/nologin`).
* The connection string with the database's host and port as the bastion
  sees them, such as `db.internal:5432`. Use the name its TLS certificate
  carries: Midplane checks it even through the bastion
  ([TLS](https://midplane.ai/docs/connect/tls.md#through-an-ssh-bastion)).

## Add the Midplane key

**1. Make the key**

In the connect form, paste the connection string first, choose
**Through an SSH bastion**, fill in **Bastion host**, **Port** and
**User**, and select **Make Midplane's key**. Its private half never
leaves the MCP server. The form shows the line to add:

```text theme={null}
restrict,port-forwarding,permitopen="db.internal:5432" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA… midplane-sshk_…
```

It names the connection string's host and port: change the string, and
copy the line again.

**2. Add the line to the bastion**

As the user Midplane logs in as:

```sh theme={null}
mkdir -p ~/.ssh && chmod 700 ~/.ssh
echo '<the line from the form>' >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
```

OpenSSH ignores the file if others can write to it or its folder. Some
systems refuse key logins to an account whose password is locked.

**3. Test and connect**

Midplane connects to the bastion, forwards to the database, and
connects over TLS. **Network**, on the source's page, then shows the
bastion, its pinned host key and Midplane's public key.

## What the key line allows

| Part | Does |
| - | - |
| `restrict` | Turns off port, agent and X11 forwarding, a terminal, and `~/.ssh/rc`. |
| `port-forwarding` | Turns port forwarding back on. |
| `permitopen="host:port"` | Forwards only to the database's host and port. |

`restrict` doesn't stop the key running a command. To make sure it can't,
give the user no login shell, or start the line with
`command="/bin/false",`: forwarding still works. Removing the source
deletes its key from Midplane; delete the line yourself.

## The pinned host key

Midplane keeps the bastion's host key from its first connection, shown as
`SHA256:…`, and refuses any other after. To check it, compare it on the
bastion with:

```sh theme={null}
for k in /etc/ssh/ssh_host_*_key.pub; do ssh-keygen -lf "$k"; done
```

A changed host key stops the source
([the SSH bastion host key changed](https://midplane.ai/docs/connect/troubleshooting.md#the-ssh-bastion-host-key-changed)).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.