SSH Cheatsheet #
SSH (Secure Shell) is a protocol for securely accessing and managing network devices and servers.
Basic Commands #
Command/Option | Example | Description |
---|---|---|
ssh | ssh user@host | Connect to a remote host as a specified user |
ssh -p | ssh -p 2222 user@host | Specify a port to connect to on the remote host (-p for port) |
ssh -i | ssh -i ~/.ssh/id_rsa user@host | Specify a private key file for authentication (-i for identity file) |
ssh -X | ssh -X user@host | Enable X11 forwarding for graphical applications (-X for X11 forwarding) |
ssh -A | ssh -A user@host | Enable agent forwarding to use local keys remotely (-A for agent forwarding) |
ssh-copy-id | ssh-copy-id user@host | Install your public key on a remote server for passwordless login |
ssh-keygen | ssh-keygen -t rsa | Generate a new SSH key pair (-t for type, e.g., rsa, dsa) |
ssh-keyscan | ssh-keyscan example.com | Retrieve the SSH public key from a server (ssh-keyscan command) |
Advanced Commands #
Command/Option | Example | Description |
---|---|---|
scp | scp file.txt user@host:/path/ | Copy files between hosts securely (scp for secure copy) |
scp -r | scp -r dir/ user@host:/path/ | Recursively copy directories (-r for recursive) |
sftp | sftp user@host | Start an interactive SFTP session for file transfers (sftp command) |
sshfs | sshfs user@host:/remote/path /local/mountpoint | Mount a remote filesystem over SSH (sshfs command) |
ssh -o | ssh -o ConnectTimeout=10 user@host | Specify SSH options, like connection timeout (-o for options) |
ssh -C | ssh -C user@host | Enable compression to speed up transfers (-C for compression) |
ssh -T | ssh -T user@host | Disable pseudo-tty allocation, useful for command execution (-T for no TTY) |
ssh -q | ssh -q user@host | Suppress warnings and error messages (-q for quiet mode) |
This cheatsheet covers the essential ssh
commands and options for secure shell access and file transfer.