SSH Connection
Connect to remote host.
ssh user@hostname
ssh -p 2222 user@hostname
ssh -i ~/.ssh/key.pem user@hostname
ssh user@hostname commandGenerate SSH Key
Create SSH key pair.
ssh-keygen
ssh-keygen -t rsa -b 4096
ssh-keygen -t ed25519
ssh-keygen -t rsa -C "email@example.com"Copy Public Key
Copy key to remote server.
ssh-copy-id user@hostname
ssh-copy-id -i ~/.ssh/id_rsa.pub user@hostname
SCP - Secure Copy
Copy files securely.
scp file.txt user@host:/path/
scp user@host:/path/file.txt ./
scp -r directory/ user@host:/path/
scp -P 2222 file.txt user@host:/path/SSH Config
Create ~/.ssh/config file.
Host myserver
HostName 192.168.1.100
User username
Port 22
IdentityFile ~/.ssh/key.pem
# Connect using:
ssh myserverPort Forwarding
Forward ports through SSH.
ssh -L 8080:localhost:80 user@host
ssh -R 8080:localhost:80 user@host
ssh -D 1080 user@hostSSH Agent
Manage SSH keys.
eval $(ssh-agent)
ssh-add ~/.ssh/id_rsa
ssh-add -l
ssh-add -DCommon mistakes / Pitfalls
- People often copy a command or pattern without adapting placeholders, which can break production workflows unexpectedly.
- It is easy to forget environment-specific differences, so always verify behavior in your shell, runtime, or API gateway before shipping.
- Many errors come from skipping small validation steps, so test with realistic sample input before relying on the result.
Last updated: February 2026