SSH Cheatsheet

A quick reference for common SSH (Secure Shell) commands.

Authentication

Command Description
ssh-keygen -t rsa -b 4096 Generate a new RSA SSH key pair.
ssh-copy-id [user]@[host] Copy your public key to a remote host for passwordless login.
ssh -i /path/to/private_key [user]@[host] Connect using a specific private key.

Basic Connection

Command Description
ssh [user]@[host] Connect to a remote host as a specific user.
ssh -p [port] [user]@[host] Connect to a host on a specific port.

File Transfer (SCP & SFTP)

Command Description
scp /path/to/local/file [user]@[host]:/path/to/remote/ Copy a file from local to remote.
scp [user]@[host]:/path/to/remote/file /path/to/local/ Copy a file from remote to local.
scp -r /path/to/local/dir [user]@[host]:/path/to/remote/ Copy a directory recursively from local to remote.
sftp [user]@[host] Start an interactive SFTP session.

Tunneling / Port Forwarding

Command Description
ssh -L [local_port]:[destination_host]:[destination_port] [user]@[gateway_host] Local port forwarding. Access a service on a remote network as if it were local.
ssh -R [remote_port]:[local_host]:[local_port] [user]@[gateway_host] Remote port forwarding. Expose a local service to a remote network.

© 2025 devcortex.ai ・ AI-powered developer tools.