A growing collection of commands and snippets I use regularly. Expand a topic below to see the details.
SSH
Secure Shell (SSH) is most commonly implemented via OpenSSH, the standard open-source SSH suite on Linux and macOS systems.
How SSH Works
graph TD; A[Local Machine] -->|Private Key| B(SSH Client); B -->|Encrypted Channel| C[Remote SSH Server]; C -->|authorized_keys| D(User Account);
Core Commands
ssh β Remote Login
Connect to a remote machine:
ssh user@host
ssh -p 2222 user@host
ssh -i ~/.ssh/id_ed25519 user@host
Port forwarding examples:
# Local forwarding
ssh -L 8080:localhost:80 user@host
# Remote forwarding
ssh -R 9090:localhost:3000 user@host
# Dynamic SOCKS proxy
ssh -D 1080 user@host
Keys & Agent
ssh-keygen β Key Management
Generate a modern key:
ssh-keygen -t ed25519 -C "you@example.com"
Other useful operations:
ssh-keygen -l -f id_ed25519.pub # fingerprint
ssh-keygen -R hostname # remove host from known_hosts
ssh-copy-id β Install Public Key
Copies your public key to a remote hostβs authorized_keys.
ssh-copy-id user@host
ssh-copy-id -i ~/.ssh/work.pub user@host
ssh-copy-id -p 2222 user@host
π Only copies public keys, never private keys.
ssh-agent β Background Key Manager
eval "$(ssh-agent -s)"
ssh-add β Load Keys Into Agent
ssh-add ~/.ssh/id_ed25519
ssh-add -l
ssh-add -D
Prevents repeated passphrase prompts.
Important SSH Files
Local (~/.ssh/):
id_ed25519β private keyid_ed25519.pubβ public keyknown_hostsβ trusted hostsconfigβ client shortcuts
Remote:
~/.ssh/authorized_keysβ allowed public keys
Correct permissions matter:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
File Transfer
scp β Secure Copy
scp file.txt user@host:/remote/path
scp -r folder user@host:/remote/path
scp user@host:/remote/file.txt .
sftp β Interactive File Transfer
sftp user@host
Inside a session:
put file.txt
get file.txt
ls
cd
rsync over SSH β Efficient Sync
rsync -avz -e ssh folder/ user@host:/remote/folder
Efficient for backups and deployments.
Server
sshd β SSH Daemon
Check status:
systemctl status sshd
Restart:
sudo systemctl restart sshd
Main config file:
/etc/ssh/sshd_config
Power Tricks
Jump Host (Bastion)
ssh -J user@jump user@internal-host
SSH Config Aliases
~/.ssh/config:
Host prod
HostName 10.0.0.10
User deploy
Port 2222
IdentityFile ~/.ssh/prod_key
Then simply:
ssh prod
Security Checklist
- Use
ed25519keys - Disable password authentication
- Disable root login
- Use a non-standard port (optional)
- Use fail2ban (optional)
- Restrict users via
AllowUsers