Connect
ssh <user>@<host>
Log in to a host
ssh <host>
Log in as your local user name
ssh -p <port> <user>@<host>
Use a non-default port
ssh <host> <command>
Run a command and return
ssh -i <keyfile> <host>
Pick a specific private key
ssh -t <host> <command>
Force a terminal (sudo, top, tmux)
ssh -v <host>
Show debug output (up to -vvv)
ssh -o <Option>=<value> <host>
Set a config option for this run
ssh -C <host>
Compress the connection
ssh -q <host>
Suppress warnings
ssh -E <logfile> -v <host>
Write debug output to a file
Keys
ssh-keygen -t ed25519 -C "<comment>"
Generate an Ed25519 key pair
ssh-keygen -t rsa -b 4096
Generate an RSA key (legacy servers)
ssh-copy-id <user>@<host>
Install your public key on a host
ssh-keygen -p -f <keyfile>
Change a key's passphrase
ssh-keygen -y -f <keyfile>
Print the public key of a private key
ssh-keygen -l -f <keyfile>
Show a key's fingerprint
ssh-keygen -R <host>
Forget a host in known_hosts
Use after a server is rebuilt and ssh warns that the host key
changed.
ssh-keyscan <host>
Fetch a host's public keys
ssh-keygen -F <host>
Find a host in known_hosts
ssh -Q key
List supported key types
Tunnels
ssh -L <lport>:<dest>:<dport>
<host>
Local forward: reach dest via host
Example: ssh -L 5433:db.internal:5432 bastion, then connect to
localhost:5433.
ssh -R <rport>:<dest>:<dport>
<host>
Remote forward: expose a local port on host
ssh -D <port> <host>
Open a local SOCKS proxy
ssh -N <host>
Forward only, run no command
ssh -f -N -L <lport>:<dest>:<dport>
<host>
Tunnel in the background
ssh -J <jump> <host>
Connect through a jump host
ssh -J <jump1>,<jump2> <host>
Chain several jump hosts
ssh -W <dest>:<port> <host>
Pipe stdin/stdout to dest via host
ssh -X <host>
Forward X11 graphical apps
ssh -Y <host>
Forward X11 with trusted mode
Config
ssh -F <file> <host>
Use another config file
ssh -G <host>
Print the effective settings
Host <alias>
Start a config block
HostName <name-or-ip>
Real address of the alias
User <user>
Default login name
IdentityFile <path>
Key to use for this host
IdentitiesOnly yes
Offer only the listed key
Stops the agent from offering many keys and tripping the
server's attempt limit.
ProxyJump <jump>
Always hop via this host
ForwardAgent yes
Forward the agent for this host
LocalForward <lport> <dest>:<dport>
Config form of -L
ServerAliveInterval 60
Send keepalives every 60 s
AddKeysToAgent yes
Auto-add keys on first use
Host *
Defaults for every host
Include <path>
Pull in more config files