Skip to content

ssh command

Log in to remote servers and run commands over a secure connection.

  • Networking
  • Package openssh-client
  • 8 options · 9 examples
On this page

Syntax

ssh [options] [user@]host [command]

Provided by the openssh-client package. Run man ssh for the full manual.

Common options

OptionWhat it does
-p PORTConnect to another port
-i FILEUse this private key
-L L:host:RForward a local port
-R R:host:LForward a remote port
-D PORTSOCKS proxy
-J HOSTJump through a bastion host
-NNo remote command (for tunnels)
-vVerbose, for debugging

Examples

  1. Connect to a server

    ssh user@192.0.2.10
  2. Use another port

    ssh -p 2222 user@server
  3. Use a specific key

    ssh -i ~/.ssh/deploy_key user@server
  4. Run one command

    ssh user@server "df -h"
  5. Create a key pair

    ssh-keygen -t ed25519 -C "you@example.com"
  6. Copy your key to a server

    ssh-copy-id user@server
  7. Forward local port 8080 to the server's 80

    ssh -N -L 8080:localhost:80 user@server
  8. Through a jump host

    ssh -J bastion.example.com user@10.0.0.5
  9. Debug a connection

    ssh -v user@server

Tips

  • Save host settings in ~/.ssh/config so you can type ssh web1.

ssh guides

← All Linux commands · Suggest a fix

Back to top