← All cheatsheets

SSH & SCP Cheatsheet

An SSH & SCP cheatsheet: connect, generate and copy keys, set up port-forwarding tunnels, copy files with scp/rsync, and write a ~/.ssh/config entry — copy-ready with editable host, user, port, and key fields.

Explain a command

Connect

  • Connect to a host
    ssh @
  • Connect on a non-default port
    ssh @ -p
  • Connect with a specific key
    ssh -i @
  • Run a single command remotely
    ssh @ ''

Keys

  • Generate an ed25519 key pair
    ssh-keygen -t ed25519 -C ""
  • Install your public key on a host
    ssh-copy-id @
  • Add a key to the agent
    ssh-add

Tunnels (port-forwarding)

  • Local forward (reach a remote service locally)
    ssh -L :: @
  • Background tunnel (no shell)
    ssh -fN -L :localhost: @
  • Remote forward (expose a local service)
    ssh -R :localhost: @
  • Dynamic SOCKS proxy
    ssh -D -fN @

Copy files

  • Copy a local file to a host
    scp @:
  • Copy a remote file down
    scp @:
  • Copy a directory recursively
    scp -r @:
  • Sync a directory over SSH (fast, resumable)
    rsync -avz -e ssh @:

Config

  • ~/.ssh/config host alias
    # ~/.ssh/config Host HostName User Port IdentityFile

    Then just `ssh <alias>`. Put this in ~/.ssh/config.

16 commands. Copy-ready with editable placeholders — everything runs in your browser, nothing is sent to a server.