SSH Connection Options
Command Line Reference
Basic Syntax
ssh [options] [user@]hostname [command]
Common Options
| Option | Description | Example |
-p port | Connect to port | ssh -p 2222 host |
-l user | Login as user | ssh -l admin host |
-i key | Use identity file | ssh -i ~/.ssh/mykey host |
-v | Verbose (debug) | ssh -vvv host |
-q | Quiet mode | ssh -q host |
-N | No command (for tunnels) | ssh -N -L 8080:localhost:80 host |
-f | Background after auth | ssh -f -N -L 8080:localhost:80 host |
-T | Disable pseudo-terminal | ssh -T host command |
-t | Force pseudo-terminal | ssh -t host sudo command |
Identity and Authentication
Specify Key File
ssh -i ~/.ssh/specific_key user@host
Multiple Keys
ssh -i ~/.ssh/key1 -i ~/.ssh/key2 user@host
Only Use Specified Keys
ssh -o IdentitiesOnly=yes -i ~/.ssh/mykey user@host
Force Password
ssh -o PreferredAuthentications=password user@host
Force Key
ssh -o PreferredAuthentications=publickey user@host
Port and Network
Custom Port
IPv4 Only
IPv6 Only
Bind to Source Address
ssh -b 192.168.1.50 user@host
Terminal Options
Force TTY Allocation
Needed for interactive commands like sudo:
ssh -t user@host sudo apt update
Force TTY (Double)
For commands that check TTY:
No TTY
For non-interactive commands:
Tunneling Options
Local Port Forward
ssh -L local_port:remote_host:remote_port user@host
ssh -L 8080:localhost:80 user@host
ssh -L 5432:database.internal:5432 user@host
Remote Port Forward
ssh -R remote_port:local_host:local_port user@host
ssh -R 8080:localhost:3000 user@host
Dynamic (SOCKS) Proxy
ssh -D local_port user@host
ssh -D 1080 user@host
Tunnel Only (No Shell)
ssh -N -L 8080:localhost:80 user@host
Background Tunnel
ssh -f -N -L 8080:localhost:80 user@host
Jump Hosts
ProxyJump (Recommended)
ssh -J jump_host user@destination
ssh -J bastion.example.com internal-server
Multiple Jumps
ssh -J jump1,jump2,jump3 user@destination
ProxyCommand (Legacy)
ssh -o ProxyCommand="ssh -W %h:%p jump_host" destination
Execution Options
Run Single Command
Run Command with Arguments
ssh user@host "grep -r 'pattern' /var/log/"
Run Local Script Remotely
ssh user@host "bash -s" < local_script.sh
Run with Environment
ssh user@host "export VAR=value; command"
Background Execution
ssh user@host "nohup ./long_running.sh &"
Host Key Options
Skip Host Key Check (Dangerous)
ssh -o StrictHostKeyChecking=no user@host
Accept New Keys Automatically
ssh -o StrictHostKeyChecking=accept-new user@host
Different Known Hosts File
ssh -o UserKnownHostsFile=/dev/null user@host
Combine (For Disposable Hosts)
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null user@host
Cipher and Algorithm Options
Specify Cipher
ssh -c chacha20-poly1305@openssh.com user@host
Specify Key Exchange
ssh -o KexAlgorithms=curve25519-sha256 user@host
Specify MAC
ssh -o MACs=hmac-sha2-256-etm@openssh.com user@host
Specify Host Key Algorithm
ssh -o HostKeyAlgorithms=ssh-ed25519 user@host
Compression
Enable Compression
Compression Level
ssh -o Compression=yes -o CompressionLevel=9 user@host
Keep-Alive
Send Keep-Alive Packets
ssh -o ServerAliveInterval=60 -o ServerAliveCountMax=3 user@host
Logging and Debugging
Verbose Levels
ssh -v user@host # Basic
ssh -vv user@host # More
ssh -vvv user@host # Maximum
Quiet Mode
Log to File
ssh -E /tmp/ssh.log user@host
Multiplexing
Master Connection
ssh -M -S /tmp/ssh-socket user@host
Use Existing Connection
ssh -S /tmp/ssh-socket user@host
Check Connection Status
ssh -S /tmp/ssh-socket -O check user@host
Close Master Connection
ssh -S /tmp/ssh-socket -O exit user@host
X11 Forwarding
Enable X11 Forwarding
Trusted X11 Forwarding
Environment
Send Environment Variable
ssh -o SendEnv=MY_VAR user@host
Set Remote Environment
ssh -o SetEnv="FOO=bar" user@host
Batch Mode
Non-Interactive (Scripts)
ssh -o BatchMode=yes user@host command
Fails immediately if interaction required.
Configuration Override
Override Config File
ssh -F /path/to/custom_config user@host
No Config File
ssh -F /dev/null user@host
Set Any Option
ssh -o "Option=value" user@host
Multiple options:
ssh -o "Option1=value1" -o "Option2=value2" user@host
Practical Examples
Debug Connection Issues
ssh -vvv user@host 2>&1 | tee ssh_debug.log
Test Key Without Login
ssh -o BatchMode=yes -o ConnectTimeout=5 user@host echo ok
Port Forward in Background
ssh -f -N -L 5432:localhost:5432 db.example.com
SOCKS Proxy for Browser
ssh -D 1080 -C -q -N proxy.example.com
Execute Multiple Commands
ssh user@host << 'EOF'
cd /var/log
ls -la
tail -n 100 syslog
EOF
Copy with Progress
ssh user@host "cat file.tar.gz" | pv > file.tar.gz
Parallel SSH (with GNU Parallel)
parallel ssh {} "uptime" ::: host1 host2 host3