ssh commands

15 commands, each with a one-line explanation. Click a command to copy it, or its title for details.

Commands 15 shown

  • ssh -i ~/.ssh/id_ed25519 user@host

    Specify an identity file explicitly

  • ssh -J bastion.example.com user@internal-host

    Single-hop jump through bastion host

    network

  • ssh -J user@bastion1,user@bastion2 user@target

    Chain multiple jump hosts in one command

    network

  • ssh -L 5432:db.internal:5432 user@bastion -N

    Forward localhost:5432 to db.internal:5432 via bastion

    network

  • ssh -R 8080:localhost:3000 user@vps -N

    Expose local port 3000 as port 8080 on VPS

    network

  • ssh -D 1080 user@vps -N -f

    Create a local SOCKS5 proxy tunnelled through VPS

    network · security

  • ssh -o ControlMaster=auto -o ControlPath=~/.ssh/mux-%r@%h:%p -o ControlPersist=10m user@host

    Reuse existing connection for subsequent SSH commands

    performance

  • ssh user@host 'sudo systemctl status nginx'

    Execute a command over SSH without interactive shell

  • scp -r -P 2222 ./dist/ user@host:/var/www/app/

    Recursive copy on non-standard port

  • ssh -A user@bastion

    Forward local SSH agent to the remote host (use with caution)

    security

  • eval $(ssh-agent) && ssh-add ~/.ssh/id_ed25519

    Start agent and load a key for the session

  • cat >> ~/.ssh/config <<'EOF' Host dev HostName 10.0.0.5 User ubuntu IdentityFile ~/.ssh/dev_key ProxyJump bastion EOF

    Shorthand alias: 'ssh dev' triggers all options

  • ~.

    Terminate a frozen/hung SSH session: type tilde then dot

    debug

  • ssh-keyscan -t ed25519,rsa host 2>/dev/null | ssh-keygen -lf -

    Fetch and fingerprint server host keys without connecting

    security

  • echo 'from="10.0.0.0/8",no-agent-forwarding,no-port-forwarding,command="/usr/bin/backup.sh" <pubkey>' >> ~/.ssh/authorized_keys

    Force-command and restrict source IP in authorized_keys

    security