Zum Inhalt springen

SSH Cheatsheet

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Terminal window
ssh user@hostname
ssh -p 2222 user@hostname
  • Establishes an interactive shell session on the remote host
  • -p specifies a custom port (default is 22)
Terminal window
ssh-keygen -t ed25519 -C "your_email@example.com"
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  • Creates public/private key pairs for passwordless authentication
  • ed25519 is recommended for new keys (more secure, faster)
Terminal window
ssh-copy-id user@hostname
  • Installs your public key on the remote host for passwordless login
  • Alternative: cat ~/.ssh/id_ed25519.pub | ssh user@hostname 'cat >> ~/.ssh/authorized_keys'
Terminal window
# From remote to local
scp user@hostname:/remote/path/file.txt ./
# From local to remote
scp ./file.txt user@hostname:/remote/path/
# Recursive copy of directories
scp -r ./localdir user@hostname:/remote/path/
  • Secure copy protocol for transferring files
Terminal window
sftp user@hostname
  • Interactive file transfer session with commands like get, put, ls, cd

Local Port Forwarding (Access remote services locally)

Section titled “Local Port Forwarding (Access remote services locally)”
Terminal window
ssh -L local_port:remote_host:remote_port user@ssh_host

Example: Access RDP through jump host

Terminal window
ssh -L 3389:10.10.202.4:3389 pfeddersheim
  • Local port 3389 on your machine forwards to 10.10.202.4:3389 via pfeddersheim
  • Connect to localhost:3389 on your local machine
Terminal window
ssh -D 1080 user@ssh_host
  • Creates a SOCKS proxy on local port 1080
  • Useful for routing all traffic through the SSH host

Remote Port Forwarding (Expose local services remotely)

Section titled “Remote Port Forwarding (Expose local services remotely)”
Terminal window
ssh -R remote_port:localhost:local_port user@ssh_host
  • Forwards remote_port on the SSH host to local_port on your local machine

Flag Description
-N No remote command execution (used with port forwarding)
-f Run in background after authentication
-T Disable pseudo-terminal allocation
-v Verbose mode (debugging)
-vvv Maximum verbose mode
-i identity_file Specify private key file
-A Enable agent forwarding
-X Enable X11 forwarding
-L Local port forwarding
-R Remote port forwarding
-D Dynamic port forwarding (SOCKS proxy)

Edit or create ~/.ssh/config:

Host jump
HostName pfeddersheim
User your_username
Port 22
Host target
HostName 10.10.202.4
User your_username
ProxyJump jump
LocalForward 3389 10.10.202.4:3389

Then connect with: ssh target