Security

SSH

SSH commands for secure remote access and tunneling.

29 commands
Windows MacOS Linux
#networking #remote-access #Popular

Connection

Connect to a remote host
ssh user@hostname
Connect on a custom port
ssh -p 2222 user@hostname
Connect using a specific key
ssh -i ~/.ssh/mykey user@host
Connect with verbose debugging output
ssh -v user@hostname
Connect via a jump host
ssh -J jumphost user@target

Key Management

Generate an Ed25519 key pair
ssh-keygen -t ed25519 -C "[email protected]"
Generate a 4096-bit RSA key pair
ssh-keygen -t rsa -b 4096
Copy public key to remote host
ssh-copy-id user@hostname
Show key fingerprint
ssh-keygen -l -f ~/.ssh/id_ed25519.pub
Remove a host from known_hosts
ssh-keygen -R hostname
Change passphrase on a key
ssh-keygen -p -f ~/.ssh/id_ed25519

Tunneling & Port Forwarding

Local port forward, remote 80 to local 8080
ssh -L 8080:localhost:80 user@host
Remote port forward, local 3000 to remote 9090
ssh -R 9090:localhost:3000 user@host
Dynamic SOCKS proxy on local port 1080
ssh -D 1080 user@host
Forward port without opening a shell
ssh -N -L 5432:dbhost:5432 user@host
Forward in background
ssh -f -N -L 8080:localhost:80 user@host

File Transfer

Copy a file to a remote host
scp file.txt user@host:/path/
Copy a file from a remote host
scp user@host:/path/file.txt .
Copy a directory recursively
scp -r ./dir user@host:/path/
Start an interactive SFTP session
sftp user@hostname
Pipe remote file to local
ssh user@host "cat /path/file" > local.txt

Config & Agent

Start the SSH agent in a new shell
ssh-agent bash
Add a private key to the agent
ssh-add ~/.ssh/id_ed25519
List keys loaded in the agent
ssh-add -l
Remove all keys from the agent
ssh-add -D
View SSH client configuration file
cat ~/.ssh/config

Quick Commands

Connect to a remote host via SSH
ssh user@hostname
Generate a new Ed25519 SSH key pair
ssh-keygen -t ed25519
Create a local port forwarding tunnel
ssh -L 8080:localhost:80 user@host