Catalog / SSH Essentials Cheatsheet
SSH Essentials Cheatsheet
A comprehensive guide to SSH (Secure Shell) commands, configuration, and usage scenarios, covering basic connections, key management, port forwarding, and more. This cheat sheet provides a quick reference for both beginners and experienced users.
Basic SSH Usage
Connecting to a Remote Server
|
Connects to the specified host as the given user. |
|
Connects to the host on a specific port. |
|
Connects using a specific private key file. |
|
Verbose mode, useful for debugging connection issues. |
|
Execute a single command on the remote host without opening a shell. |
|
Quiet mode, suppresses most warning and diagnostic messages. |
SSH Configuration File (~/.ssh/config)
The Example:
Now you can simply use |
Common SSH Options
|
The actual hostname or IP address of the server. |
|
The username to use for the connection. |
|
The port number to connect to (default is 22). |
|
Specifies the private key file for authentication. |
|
Controls how SSH handles unknown host keys ( |
|
Command to use to connect to the server. |
Key Management
Generating SSH Keys
|
Generates a new SSH key pair (private and public key). Example: |
|
Generates a new Ed25519 SSH key pair (private and public key). Example: |
|
Generates a new RSA SSH key pair with 4096 bits. |
|
Creates a key without prompting. |
Copying Keys to Remote Servers
|
Copies your public key to the remote server’s Example: |
|
Alternative method to copy the public key manually. |
|
Copy the public key to clipboard. |
Key Security
Always protect your private key. Ensure it has appropriate permissions (e.g., |
Use a strong passphrase when generating your SSH key. This adds an extra layer of security. |
Port Forwarding
Local Port Forwarding
|
Forwards traffic from Example: |
|
Access the web server on 192.168.1.10 on your machine. |
Remote Port Forwarding
|
Forwards traffic from Example: |
Dynamic Port Forwarding (SOCKS Proxy)
|
Creates a SOCKS proxy on Example: |
|
Background the process and don’t execute a remote command. |
Common Options
|
Advanced SSH Usage
Executing Commands Remotely
|
Executes a single command on the remote host. Example: |
|
Executes multiple commands using a ‘here document’. Example:
|
|
Execute a shell script. Example: |
SCP (Secure Copy)
|
Copies a file to a remote host. Example: |
|
Copies a file from a remote host. Example: |
|
Copies a directory recursively to a remote host. Example: |
|
Copies a file from a remote host on a specific port. Example: |
SSH Agent Forwarding
|
Enables agent forwarding, allowing you to use your local SSH keys on the remote server for further connections. Use with caution, as it can pose a security risk. Note: Ensure |
|
Enables agent forwarding, allowing you to use your local SSH keys on the remote server for further connections. Use with caution, as it can pose a security risk. |
Mosh (Mobile Shell)
Mosh is a mobile shell that provides a more robust and responsive connection, especially over unreliable networks. It tolerates intermittent connectivity and IP address changes. Basic Usage:
|