SSH Cheat Sheet
A quick reference for SSH, connecting to remote hosts, generating and copying keys, transferring files with scp and rsync, local and remote port forwarding, and the SSH config file.
A quick reference to the SSH client and friends. Replace user,
host, PORT, and KEY with your own values.
Square brackets mark optional parts.
Connecting
| Command | What it does |
|---|---|
ssh user@host | Open an interactive shell on the remote host |
ssh -p PORT user@host | Connect on a non-default port |
ssh -i KEY user@host | Use a specific private key file |
ssh user@host "cmd" | Run one command remotely and return |
ssh -J jump user@host | Connect through a jump (bastion) host |
Keys
| Command | What it does |
|---|---|
ssh-keygen -t ed25519 | Generate a modern Ed25519 key pair |
ssh-keygen -t rsa -b 4096 | Generate a 4096-bit RSA key pair |
ssh-copy-id user@host | Install your public key on the remote host |
ssh-keygen -lf KEY | Show a key's fingerprint |
ssh-keygen -R host | Remove a host from known_hosts (after a change) |
Copying files
| Command | What it does |
|---|---|
scp FILE user@host:/path | Copy a local file to the remote host |
scp user@host:/path FILE | Copy a remote file back here |
scp -r DIR user@host:/path | Copy a whole directory recursively |
rsync -avz DIR/ user@host:/path/ | Sync a folder, only sending changes |
sftp user@host | Open an interactive file transfer session |
Port forwarding (tunnels)
| Command | What it does |
|---|---|
ssh -L 8080:localhost:80 user@host | Local tunnel: reach a remote service from your machine |
ssh -R 8080:localhost:80 user@host | Remote tunnel: expose a local service to the remote host |
ssh -D 1080 user@host | Dynamic SOCKS proxy through the remote host |
ssh -L 8080:localhost:80 -N user@host | Forward only, no shell (-N) |
Config file (~/.ssh/config)
| Snippet | What it does |
|---|---|
Host dev | Define a short alias for a host block |
HostName example.com | The real address the alias connects to |
User deploy | Default username for the alias |
IdentityFile ~/.ssh/dev | Private key to use for the alias |
Agent
| Command | What it does |
|---|---|
eval $(ssh-agent) | Start the agent in the current shell |
ssh-add KEY | Load a private key into the agent |
ssh-add -l | List keys currently held by the agent |
Tip: define Host blocks in ~/.ssh/config so you
can type ssh dev instead of ssh -i ~/.ssh/dev -p 2222 deploy@example.com.
Lock the server down by disabling password login once keys work.
What this does
An SSH cheat sheet covers connecting to remote hosts, generating and copying keys, transferring files with scp and rsync, port forwarding, and the SSH config file.
How to use it
- Browse by section.
- Find the command you need.
- Copy it with one tap.
- Replace the host, user, and port.
Example
ssh user@example.com opens an interactive shell on the remote host.
Sources & methodology
Last updated .
Frequently asked questions
Key-based or password login — which is better?
Keys are stronger and more convenient. Generate a key pair with ssh-keygen, copy the public key with ssh-copy-id, then disable password login in the server config for better security.
Why do I get permission denied (publickey)?
Your private key is not being offered, usually because of wrong permissions. Run chmod 700 ~/.ssh and chmod 600 on the key file, and check that the public key is in the server’s authorized_keys file.
How do I keep a connection from dropping?
Add ServerAliveInterval 60 and ServerAliveCountMax 3 to your SSH config so the client sends a keepalive packet every minute and tolerates a few missed replies.
Related tools
Linux Command Cheat Sheet
The essential Linux terminal commands on one page, files and navigation, permissions, processes, networking, and package managers. A quick reference for the bash shell.
Windows CMD Cheat Sheet
A quick reference for the Windows Command Prompt, file and folder commands, networking, disk and system tools, plus handy keyboard shortcuts.
PowerShell Cheat Sheet
A reference for Windows PowerShell, discovering cmdlets, the object pipeline, filtering and formatting, managing files, processes and services, plus variables and flow control.
macOS Terminal Cheat Sheet
A reference for the macOS Terminal, the Mac-only commands (open, pbcopy, mdfind), system and defaults tools, Homebrew, core Unix commands, and keyboard shortcuts.