SSH Cheatsheet
This cheatsheet provides a comprehensive and practical reference for common SSH commands. It covers connection, key management, config, file transfer, tunneling, security, command combos, and more. Use it to boost your productivity in remote management and automation.
Use the search bar to quickly find specific SSH commands or browse through categories for a complete reference. Explore the Command Combos section for powerful multi-step workflows.
Basic Usage
ssh user@host
Connect to a remote host via SSH
ssh -p 2222 user@host
Connect using a custom port
ssh -i ~/.ssh/id_rsa user@host
Connect with a specific private key
ssh -v user@host
Verbose output for debugging
ssh -X user@host
Enable X11 forwarding
ssh -A user@host
Enable SSH agent forwarding
ssh -t user@host 'bash -l'
Force pseudo-terminal allocation
Key Management
ssh-keygen -t rsa -b 4096 -C '[email protected]'
Generate a new RSA SSH key pair
ssh-copy-id user@host
Copy public key to remote host for passwordless login
ssh-add ~/.ssh/id_rsa
Add private key to SSH agent
ssh-agent bash
Start a new SSH agent session
cat ~/.ssh/id_rsa.pub
Show your public key
ssh-keyscan host
Get public key from a remote host
Config & Multiplexing
vim ~/.ssh/config
Edit SSH client config file
Host myserver
HostName example.com
User user
Port 2222
Sample SSH config entry
ssh myserver
Connect using config alias
ssh -M -S /tmp/ssh_mux user@host
Start a master connection for multiplexing
ssh -S /tmp/ssh_mux -O check user@host
Check multiplexed connection status
ssh -S /tmp/ssh_mux -O exit user@host
Close multiplexed connection
File Transfer
scp file.txt user@host:/path/
Copy file to remote host
scp user@host:/path/file.txt ./
Copy file from remote host
scp -r dir/ user@host:/path/
Recursively copy directory to remote host
rsync -avz file.txt user@host:/path/
Sync file to remote host using rsync
rsync -avz user@host:/path/ ./
Sync file from remote host using rsync
sftp user@host
Start SFTP session
Tunneling & Port Forwarding
ssh -L 8080:localhost:80 user@host
Forward local port 8080 to remote 80
ssh -R 9090:localhost:22 user@host
Forward remote port 9090 to local 22
ssh -D 1080 user@host
Create a SOCKS proxy on local port 1080
ssh -N -L 3306:dbhost:3306 user@host
Forward MySQL port without executing remote command
ssh -f -N -L 5901:localhost:5901 user@host
Run SSH tunnel in background
Advanced & Security
ssh -o StrictHostKeyChecking=no user@host
Disable host key checking (not recommended)
ssh -C user@host
Enable compression
ssh -4 user@host
Force IPv4
ssh -6 user@host
Force IPv6
ssh -l user host
Specify user with -l option
ssh -F /path/to/config user@host
Use custom SSH config file
Command Combos
ssh user@host 'df -h'
Run a remote command and exit
ssh user@host 'tar czf - /dir' | tar xzf - -C /dest
Backup remote directory to local machine
for host in host1 host2; do ssh $host 'uptime'; done
Run a command on multiple hosts
ssh -J jumpuser@jump hostuser@target
Jump host (ProxyJump) connection
ssh user@host 'sudo reboot'
Reboot remote host via SSH
Categories
- Basic Usage
Connect to remote hosts, use custom ports, keys, and options.
- Key Management
Generate, copy, and manage SSH keys and agents.
- Config & Multiplexing
Configure SSH client, aliases, and multiplexing connections.
- File Transfer
Transfer files and directories using SCP, SFTP, and rsync.
- Tunneling & Port Forwarding
Forward ports, create SOCKS proxies, and tunnels.
- Advanced & Security
Advanced options, security, compression, IPv4/6, and custom config.
- Command Combos
Powerful multi-step workflows and advanced usage patterns for real-world scenarios.
Features
- Quick search functionality
- Organized by categories
- Clear command descriptions
- Common and advanced use cases covered
- Easy to copy commands
- Responsive design
- Perfect for quick reference