SSH Basics
Secure Shell connection, keys, and configuration.
SSH Connection
# Basic connection
ssh user@hostname
ssh [email protected]
# Specify port
ssh -p 2222 user@hostname
# Use specific key
ssh -i ~/.ssh/id_rsa user@hostname
SSH Key Generation
# Generate RSA key
ssh-keygen -t rsa -b 4096
# Generate Ed25519 key
ssh-keygen -t ed25519
# Specify output file
ssh-keygen -f ~/.ssh/my_key
Copy SSH Key
# Copy public key to server
ssh-copy-id user@hostname
# Set correct permissions
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
SSH Config File
# ~/.ssh/config
Host myserver
HostName 192.168.1.10
User ubuntu
Port 22
IdentityFile ~/.ssh/id_rsa
# Connect using alias
ssh myserver
SSH Tunneling
# Local port forwarding
ssh -L 8080:localhost:80 user@server
# Remote port forwarding
ssh -R 8080:localhost:80 user@server
# Dynamic forwarding
ssh -D 8080 user@server