ssh
Quick Reference
Command Name:
ssh
Category:
networking
Platform:
Linux/Unix/Windows
Basic Usage:
Common Use Cases
- 1
Secure remote access
Connect securely to remote servers with encrypted communications
- 2
Remote command execution
Run commands on remote systems without establishing a full shell
- 3
Port forwarding
Create secure tunnels to access services behind firewalls or NAT
- 4
Jump host connections
Connect to servers through intermediary proxy systems
Syntax
ssh [options] [user@]hostname [command]
Options
Option | Description |
---|---|
-4 | Force SSH to use IPv4 addresses only |
-6 | Force SSH to use IPv6 addresses only |
-A | Enable forwarding of the authentication agent connection |
-C | Enable compression of all data |
-D [bind_address:]port | Dynamic port forwarding (SOCKS proxy server) |
-F configfile | Specify an alternative per-user configuration file |
-i identity_file | Specify identity (private key) file |
-J [user@]host[:port] | Connect through a jump host (SSH proxy) |
-L [bind_address:]port:host:hostport | Local port forwarding |
-N | Do not execute a remote command (useful for port forwarding) |
-o option | Specify options in the format used in the config file |
-p port | Connect to this port on the remote host |
-q | Quiet mode (suppress most warning and diagnostic messages) |
-R [bind_address:]port:host:hostport | Remote port forwarding |
-t | Force pseudo-terminal allocation (interactive programs) |
-v | Verbose mode (useful for debugging) |
-X | Enable X11 forwarding |
-Y | Enable trusted X11 forwarding (less secure but more compatible) |
Common SSH Config File Options:
Option | Description |
---|---|
Host | Specifies host patterns for which the following declarations apply |
HostName | Real hostname to connect to (allows for aliases) |
User | Username to use when connecting |
Port | Port to connect to on the remote host |
IdentityFile | File from which the identity (private key) is read |
ForwardAgent | Whether to forward the SSH agent |
ForwardX11 | Whether to forward X11 connections |
ServerAliveInterval | Seconds between keepalive packets |
PasswordAuthentication | Whether to use password authentication |
ProxyJump | Host to use as a jump host |
Examples
How to Use These Examples
The examples below show common ways to use the ssh
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
ssh user@hostname
Connect to a remote server with a specific username.
ssh hostname
Connect to a remote server using your current username.
ssh -p 2222 user@hostname
Connect to a remote server on a non-standard port.
Running Remote Commands:
ssh user@hostname ls -la
Run a command on the remote server and return the output.
ssh user@hostname "cat /etc/hostname && uptime"
Run multiple commands on the remote server.
Key Authentication:
ssh-keygen -t rsa -b 4096
Generate an RSA SSH key pair with 4096 bits.