SSH cheatsheet
Connecting
| Command | Description |
|---|---|
ssh user@host | Interactive login |
ssh -p 2222 user@host | Connect on custom port |
ssh -i ~/.ssh/deploy_key user@host | Use specific private key |
ssh user@host 'uptime' | Run remote command |
ssh -J bastion user@internal | Jump through bastion (ProxyJump) |
ssh -L 8080:localhost:80 user@host | Local port forward |
ssh -R 9000:localhost:3000 user@host | Remote port forward |
Keys
| Command | Description |
|---|---|
ssh-keygen -t ed25519 -C "you@host" | Generate Ed25519 key pair |
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@host | Install public key on server |
ssh-keygen -lf ~/.ssh/id_ed25519.pub | Show key fingerprint |
ssh-add ~/.ssh/id_ed25519 | Add key to ssh-agent |
ssh-add -l | List loaded agent keys |
File transfer
| Command | Description |
|---|---|
scp file user@host:/path/ | Copy file to remote |
scp -r dir/ user@host:/path/ | Copy directory recursively |
scp -P 2222 file user@host: | scp with custom port |
sftp user@host | Interactive SFTP session |
rsync -avz -e ssh src/ user@host:dest/ | Sync over SSH |
Server management
| Command | Description |
|---|---|
systemctl status ssh | SSH service status (Debian/Ubuntu) |
systemctl status sshd | SSH service status (RHEL/CentOS) |
sshd -t | Test sshd_config syntax |
ss -tlnp | grep :22 | Confirm sshd is listening |
journalctl -u ssh -n 50 | Recent SSH logs (systemd) |
Debugging
| Command | Description |
|---|---|
ssh -v user@host | Verbose connection debug |
ssh -vvv user@host | Maximum verbosity |
ssh-keygen -R host | Remove stale known_hosts entry |
grep sshd /var/log/auth.log | Auth log (Debian/Ubuntu) |
grep sshd /var/log/secure | Auth log (RHEL/CentOS) |
Example ~/.ssh/config
Host bastion
HostName jump.example.com
User deploy
IdentityFile ~/.ssh/deploy_ed25519
Host app-*
User ubuntu
ProxyJump bastion
IdentityFile ~/.ssh/deploy_ed25519
Pro tips
- Prefer Ed25519 keys over RSA unless legacy systems require RSA
- Use
ssh -vvvon the client and auth logs on the server together - Run
sshd -tbefore reloading sshd — a syntax error can lock you out - Keep a second session open when changing
sshd_configremotely
Practice scenarios
Hands-on SSH scenarios on live Linux VMs: ssh