SSH, Bastions and VPNs
Access remote machines and private networks securely using SSH keys, jump hosts, tunnels and modern VPNs.
Intermediate · about 4 hours · difficulty 2/5
Learn first: Firewalls, Security Groups and NAT
SSH is how you reach servers, and VPNs are how you reach private networks. Both need to be set up securely because they are the front door for attackers too.
SSH done right
- Use key-based auth (
ssh-keygen -t ed25519), disable password login and root login insshd_config. - An ssh-agent holds unlocked keys; agent forwarding is convenient but risky on shared hosts.
~/.ssh/configwithHost,User,IdentityFileandProxyJumpmakes access to many hosts painless.- Tunnels: local forward (
-L 5432:db:5432) to reach a private database, remote forward (-R), and dynamic SOCKS (-D). scp,rsync -avzandsftpfor files.
Reaching private networks
- Bastion (jump) hosts as the single hardened entry point.
- Keyless alternatives: AWS Systems Manager Session Manager, GCP IAP, Azure Bastion, or SSH certificates from a CA.
- VPNs: WireGuard (simple, fast), OpenVPN, IPsec for site-to-site, and mesh VPNs like Tailscale.
Pitfalls
Sharing one private key across a team, leaving old public keys in authorized_keys, and bastions with open-to-the-world SSH and no logging.
Good enough to move on: you can reach a database in a private subnet through a jump host with one ssh command, and explain why session managers are replacing bastions.
Key concepts
- Key-based auth and sshd hardening
- ssh config and ProxyJump
- Port forwarding and tunnels
- rsync and scp
- Bastion hosts
- Session Manager / IAP
- WireGuard and OpenVPN
- SSH certificates
Mini project
Set up two VMs where only one has a public IP, configure ProxyJump in ~/.ssh/config to reach the private one, and open a local tunnel to a database running on it.
Check yourself
Why is ssh agent forwarding to a shared bastion considered risky, and what does ProxyJump do differently?
Free resources
- OpenSSH manual pages (OpenBSD)
- WireGuard (wireguard.com)