Skip to content
ohsudo, Home
Linux

SSH Cheat Sheet

The SSH commands you use every day: connecting, keys, the config file, jump hosts, tunnels, copying files, permissions, the server side and the common errors.

Updated November 15, 2026 · Applies to OpenSSH 8+ · Linux · macOS · Windows 10+

Connect

Terminal window
ssh user@server
ssh -p 2222 user@server # another port
ssh -i ~/.ssh/deploy_ed25519 user@server
ssh -J bastion user@10.0.1.20 # through a jump host
ssh user@server 'df -h /' # run one command
ssh -t user@server 'sudo journalctl -f' # command that needs a terminal
ssh -v user@server # debug: -vv, -vvv for more

Keys

Terminal window
ssh-keygen -t ed25519 -C "anna@laptop" # new key pair
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server
ssh-add ~/.ssh/id_ed25519 # load into the agent
ssh-add -l # keys in the agent
ssh-keygen -lf ~/.ssh/id_ed25519.pub # fingerprint
ssh-keygen -p -f ~/.ssh/id_ed25519 # change the passphrase
ssh-keygen -R server # forget a host key

~/.ssh/config

Host web1
HostName 203.0.113.10
User deploy
Port 2222
IdentityFile ~/.ssh/deploy_ed25519
IdentitiesOnly yes
Host 10.0.1.*
ProxyJump bastion
Host *
ServerAliveInterval 30

Then just ssh web1. ssh -G web1 prints the settings that apply. The SSH Config Generator writes this file for you.

Tunnels

Terminal window
ssh -L 5432:localhost:5432 user@db # local 5432 → db's own 5432
ssh -L 8080:10.0.1.5:80 user@bastion # local 8080 → a host behind bastion
ssh -R 9000:localhost:3000 user@server # server's 9000 → your 3000
ssh -D 1080 user@server # SOCKS proxy on local 1080
ssh -fN -L 5432:localhost:5432 user@db # in the background, no shell

Copy files

Terminal window
scp file.txt user@server:/tmp/
scp -r user@server:/var/log/app ./logs
rsync -avz --progress ./site/ user@server:/var/www/site/
rsync -avz -e 'ssh -p 2222' ./data/ user@server:/data/
sftp user@server

With zsh, quote remote patterns: scp 'server:/var/log/*.log' .

Permissions

Terminal window
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519 ~/.ssh/authorized_keys ~/.ssh/config
chmod 644 ~/.ssh/id_ed25519.pub

On the server, the home folder must not be writable by others either.

The server

Terminal window
sudo sshd -t # test sshd_config
sudo sshd -T | grep -i passwordauth # settings in effect
sudo systemctl reload ssh # "sshd" on RHEL-based systems
sudo journalctl -u ssh -f # login attempts and errors
sudo ssh-keygen -A # recreate missing host keys

Keep a second session open while you change sshd_config.

Escape sequences

Type them at the start of a line, after Enter:

Keys Does
~. Close a frozen connection
~C Command line: add a -L tunnel to the open session
~? List them

Common errors

Other cheat sheets