SSH (Secure Shell) for remote access, file transfer, and secure communications.
SSH Keys vs Passwords
SSH keys provide better security and convenience than passwords.
Generate Keys
|
|
Deploy Public Key
|
|
Basic Operations
|
|
SSH Config
~/.ssh/config:
Host prod
HostName server.example.com
User na
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
Host staging
HostName staging.example.com
User deploy
Port 2222
Host *
Compression yes
ControlMaster auto
ControlPath ~/.ssh/master-%h:%r:%p
ControlPersist 60
Usage:
|
|
Connection Multiplexing
Reuse existing connections for speed:
Host *
ControlMaster auto
ControlPath ~/.ssh/master-%h:%r:%p
ControlPersist 10m
First connection creates a master socket. Subsequent connections reuse it (instant login, no re-authentication).
Agent Forwarding
Use local SSH keys on remote servers:
Host jumphost
HostName jump.example.com
ForwardAgent yes
Security warning: Only use on trusted servers.
Jump Hosts
Connect through intermediate servers:
Host internal
HostName internal.local
ProxyJump jumphost
Or command line:
|
|
Tips
- Never share private keys
- Use strong passphrases for private keys
- Keep
~/.sshpermissions at700 - Keep private keys at
600permissions - Use
ssh-agentto avoid repeatedly entering passphrases - Disable root login on servers:
PermitRootLogin no - Use key-based auth exclusively:
PasswordAuthentication no