Cheat Sheet Library

SSH & SCP Cheat Sheet

Log in to remote machines securely and copy files between them. Works the same on Linux, macOS, Git Bash, WSL and Windows 10+ (OpenSSH is built in).

  • 35 entries
  • 8 sections
  • Updated
  • Click a command to see all its options

35 entries

On this page

Connecting #

CommandAction
Connect
Connect on a different port
Use a specific key
Run one command and return
Connect through a jump host
Verbose output (debug connection problems)
exit or Ctrl + DDisconnect
Enter, then ~.Kill a frozen session

Keys #

CommandAction
Create a key pair (recommended type)
Install your public key on a server (then no password needed)
Show your public key (this part is safe to share)
then Load the key into the agent (type the passphrase once)
Keys loaded in the agent
Remove an old host key ("REMOTE HOST IDENTIFICATION HAS CHANGED")
Change the passphrase

Windows without ssh-copy-id: type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh user@host "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

~/.ssh/config (shortcuts) #

Host pi
    HostName 192.168.1.50
    User milan
    Port 22
    IdentityFile ~/.ssh/id_ed25519

Host *
    ServerAliveInterval 60

Now ssh pi, scp file pi:~ and VS Code Remote-SSH all understand pi.

Copying Files (scp) #

CommandAction
Upload
Download to the current folder
Upload a folder
Custom port (capital P!)
Copy between two remote hosts

rsync (better for big or repeated copies) #

CommandAction
Sync a folder (only sends changes)
With progress
Mirror (deletes extra files on the destination)
Custom port
Dry run: show what would happen

A trailing / on src/ copies the contents. Without it, the folder itself is copied.

Port Forwarding (Tunnels) #

CommandAction
Local: your localhost:8080 → the server's port 80
Reach a private database through a server
Remote: the server's port 9000 → your local 3000
SOCKS proxy through the server
Tunnel only, in the background

Server Side (sshd) #

Command / settingAction
Install the SSH server (Debian/Ubuntu)
/etc/ssh/sshd_configServer configuration
PasswordAuthentication noKeys only (set up your key first!)
PermitRootLogin noBlock root login
Apply changes (sshd on Fedora/Arch)

Permissions (common "bad permissions" error) #

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