Set up a reverse-tunnel bastion
on this page
Provision and harden a Linux VM that Windows targets on a private network can dial out to with a reverse SSH tunnel. You set up the bastion once for the whole fleet, then add each target with Onboard a target through a reverse-tunnel bastion.
Preflight does not create or manage the tunnel. It only connects through the bastion as an SSH jump host. To decide whether this pattern fits your network, see Deploy across restricted networks.
Prerequisites
- An always-on Debian or Ubuntu VM with a public IP. The commands below use
aptandufw; adjust them for other distributions. sudoaccess on the VM, through an account that logs in with an SSH key
Each target needs the OpenSSH client to open the tunnel and OpenSSH Server so Preflight can log in through it. Both ship with Windows.
1. Create the admin and tunnel users
Create one account for operators and one for tunnels, so a stolen target key cannot reach the operator account:
sudo adduser admin
sudo usermod -aG sudo admin
sudo adduser --disabled-password --shell /usr/sbin/nologin tunnel
sudo install -d -m 700 -o tunnel -g tunnel /home/tunnel/.sshCopy your current key to admin before you disable password logins, or you will lock yourself out:
sudo install -d -m 700 -o admin -g admin /home/admin/.ssh
sudo install -m 600 -o admin -g admin ~/.ssh/authorized_keys /home/admin/.ssh/authorized_keysThe tunnel user gets keys later, one per target, during onboarding.
2. Lock down sshd
Add these settings to /etc/ssh/sshd_config, or to a file in /etc/ssh/sshd_config.d/:
PermitRootLogin no
PasswordAuthentication no
GatewayPorts noGatewayPorts no binds every reverse-forwarded port to 127.0.0.1 on the bastion, so no forwarded port is reachable from the internet. Only a session already on the bastion can connect to it.
Check the config and restart sshd:
sudo sshd -t
sudo systemctl restart sshKeep your current session open. In a second terminal, confirm ssh admin@<bastion> still works.
3. Restrict the firewall
Allow inbound SSH and nothing else:
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp
sudo ufw enable4. Install baseline hardening
sudo apt update
sudo apt install -y fail2ban unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgradesfail2ban bans IPs that repeatedly fail SSH authentication. unattended-upgrades installs security patches automatically.
5. Verify
-
adminlogs in with a key -
sudo sshd -T | grep -E 'permitrootlogin|passwordauthentication|gatewayports'printsnofor all three -
tunnelhas no password and/usr/sbin/nologinas its shell -
sudo ufw statusallows only22/tcpinbound -
systemctl is-active fail2ban unattended-upgradesprintsactivetwice
Troubleshooting
| Symptom | Cause |
|---|---|
| Locked out after restarting sshd | admin had no authorized_keys when password logins were disabled. Fix sshd_config through your provider’s recovery console. |
Connection refused on port 22 | ufw is enabled without the 22/tcp rule. Check sudo ufw status from the provider console. |
| A forwarded port is reachable from outside the bastion | GatewayPorts is not no, or sshd was not restarted. Check sudo sshd -T | grep gatewayports. |