SSH keys, bastions and remote access

Intermediate · 10 min

Reach private servers without exposing them: key-only SSH, one hardened bastion host, ProxyJump on the client, and why agent forwarding is the risky shortcut.

Before thisThe Linux server from an operator's seatRunning services with systemd

ByteMonk · 10 min

SSH keys, bastions and remote access

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by ByteMonkReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • Any SSH port open to the internet is scanned and password-guessed within minutes, so production servers accept keys only and refuse root logins.
  • A bastion, or jump host, is the one machine with SSH reachable from outside. Every other server accepts SSH only from the bastion's address.
  • ProxyJump makes the bastion a relay. Your laptop opens an encrypted session straight to the private server through it, and your private key never leaves your laptop.
  • Agent forwarding lets anyone with root on the bastion use your keys while you are connected, which is why ProxyJump is the better default.
  • Give each person their own key and account, so access can be removed for one person and every login is traceable.

The problem: a door everyone can knock on

A server you cannot reach is useless, so you open port 22 and SSH in. Within minutes, automated scanners find it and start guessing usernames and passwords. They try root/123456, admin/admin, and thousands more, all day. With one server and a strong password you might be fine. With forty servers, several engineers and an ex-contractor whose password nobody changed, you are relying on luck.

Two ideas fix this. Make the door unpickable, by allowing keys only. Then reduce the number of doors to one, by putting the servers behind a bastion.

Keys, not passwords

You already know key-based login from remote work with ssh and from GitHub’s SSH keys: a private key stays on your machine, the matching public key goes into ~/.ssh/authorized_keys on the server, and the server checks that you hold the private half without ever receiving it. I generated a key pair in a scratch directory:

$ ssh-keygen -t ed25519 -C "deploy@laptop" -N "" -f ./id_ed25519 -q
$ cat id_ed25519.pub
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICWn7x8w5QHOMq/xDFOwJaM0KEe9h4Og4YFjpEiPyKDg deploy@laptop
$ ssh-keygen -lf id_ed25519.pub
256 SHA256:JUkAdtUIUagGNIA9LnpBmLX8JACeaq3lBnVKAzJVc0I deploy@laptop (ED25519)

I used an empty passphrase (-N "") only because this is a throwaway. A real key gets a passphrase, held by ssh-agent so you type it once per session.

The operator’s job is on the server side. These are the usual lines in /etc/ssh/sshd_config, from the sshd_config man page. I did not apply them, because I had no server:

PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin no

People log in as themselves and use sudo. That way every action is attributable, and removing someone means deleting one account, not rotating a shared password. Keep a second session open while you reload sshd, so a typo does not lock you out.

One door: the bastion

A bastion, also called a jump host, is a small machine whose only job is to be the entry point. It is the only host with SSH reachable from the internet, it runs almost nothing else, and it logs every session. Your application and database servers sit in a private network. Their firewall, or the cloud’s security group, accepts SSH only from the bastion’s address. You will build that rule in virtual networks, subnets and security groups.

Think of a building with one staffed reception desk instead of a key to every office’s outside door. You can still reach any office, but only through the one place that checks badges.

ProxyJump: going through, not stopping on

The naive way to use a bastion is to SSH to it, then SSH again from there. That means your private key, or a copy, has to be on the bastion. OpenSSH’s ProxyJump does better: your laptop asks the bastion to open a plain TCP connection to the private server, and then runs a second, end-to-end encrypted SSH session through that tunnel. The bastion relays bytes it cannot read.

You set it once in ~/.ssh/config. I wrote this in a scratch config, with made-up hosts:

Host bastion
    HostName bastion.example.net
    User me
    IdentityFile ./id_ed25519

Host app-*
    ProxyJump bastion
    User deploy
    IdentityFile ./id_ed25519

Host app-1
    HostName 10.0.2.15

ssh -G prints the configuration ssh would use, without connecting:

$ ssh -F config -G app-1 | grep -E '^(hostname|user|port|proxyjump|forwardagent) '
user deploy
hostname 10.0.2.15
port 22
forwardagent no
proxyjump bastion

Then I tried to connect for real, with -v. The bastion does not exist, so it fails, but the debug output shows the order of events (trimmed):

$ ssh -F config -o BatchMode=yes -o ConnectTimeout=3 -v app-1 true
debug1: Setting implicit ProxyCommand from ProxyJump: ssh -F config -v -W '[%h]:%p' bastion
debug1: Executing proxy command: exec ssh -F config -v -W '[10.0.2.15]:22' bastion
debug1: Connecting to bastion.example.net port 22.
ssh: Could not resolve hostname bastion.example.net: nodename nor servname provided, or not known

ssh first starts a second ssh to the bastion with -W '[10.0.2.15]:22', which means “forward my stdin and stdout to that address”. The laptop never tries to reach 10.0.2.15 itself, and it doesn’t need to, because that address only exists inside the private network. The bastion must allow TCP forwarding for -W to work (AllowTcpForwarding in its sshd_config). That was OpenSSH 10.5p1 on macOS.

The shortcut to avoid

ssh -A forwards your SSH agent to the bastion, so the second hop can use your keys. It works, and it is risky. While you are connected, anyone with root on the bastion can use your agent’s socket to sign logins as you, to any server your key opens. ProxyJump gets you to the same place without lending your agent to anyone.

Many teams now skip public SSH entirely. Cloud services such as AWS Systems Manager Session Manager or Google’s Identity-Aware Proxy, and tools like Teleport, put an identity-checked, logged gateway in front of servers. They are the same bastion idea, built by someone else.

About the video

“What EXACTLY is Bastion? | SSH Jump, Port Forwarding & Netflix” is from ByteMonk, published August 2025, 10 minutes. Its chapters cover the problem bastions solve, how they work, ProxyJump, a local port forwarding example, chaining bastions, Netflix’s bastion setup, managed alternatives (AWS SSM, Google IAP, Teleport), and when not to use one. It does not cover hardening sshd or key handling on the server, which this lesson adds. English was judged from the title, description, channel and its English auto-caption track. ExitZero’s video in deeper is a hands-on configuration walkthrough.

Where this fits

You can reach your servers. Next, how clients find them by name, and how long a change to that name takes to reach everyone: DNS records and TTLs in practice.

Check yourself

  1. 01Why is PasswordAuthentication no a standard first change on a new server?

    Bots try common passwords against every public SSH port. With passwords off, there is nothing to guess, because only someone holding an authorised private key can log in.

  2. 02What does a bastion host change about your network's exposure?

    Only one machine accepts SSH from the internet, and it runs little else. Private servers have no public SSH at all, so there is one door to harden, watch and log.

  3. 03With ProxyJump, where does the SSH session to the private server get decrypted?

    Only on your laptop and on the private server. The bastion forwards an encrypted TCP stream and never sees your keys or the session contents.

  4. 04Why is ssh -A to a bastion risky?

    It exposes your SSH agent on the bastion. Anyone with enough access there can ask your agent to sign logins to other servers for as long as you are connected.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark