hennes' SSH cheatsheet

Create key pair (in 2024)

# Ed25519
ssh-keygen -t ed25519

# with email as commentary
ssh-keygen -t ed25519 -C "me@example.com"

# RSA
ssh-keygen -t rsa -b 4096

# with email as commentary
ssh-keygen -t rsa -b 4096 -C "me@example.com"

Copy public key to authorized keys on remote server

cat id_rsa.pub | ssh USER@SERVER 'cat>> ~/.ssh/authorized_keys'

or alternatively

ssh-copy-id -i ~/.ssh/id_rsa.pub USER@SERVER

Port forwarding

ssh -NfL LOCAL_PORT:TARGET_IP_ON_REMOTE_HOST:TARGET_PORT_ON_REMOTE_HOST USER@SERVER

No -f to keep ssh process in foreground.

Example

Forward port to remote MySQL at example.com on local port 3307:

ssh -NfL 3307:127.0.0.1:3306 bob@example.com

Show fingerprint

This is useful to check the key length of a key.

ssh-keygen -lf ~/.ssh/id_rsa.pub