SSH Basics
SSH (Secure Shell) is how you connect to remote servers. If you work with servers, you'll use SSH daily.
Basic Connection
You're now on the remote server. Run commands there. Type exit to disconnect.
SSH with IP Address
Specify Port
SSH Keys (The Better Way)
Password authentication works, but keys are:
- More secure
- More convenient (no typing passwords)
- Required by many services (GitHub, AWS)
Generate a Key Pair
Key Types
ed25519 is modern and secure. rsa (4096 bit) is the older alternative. Avoid dsa.
Copy Key to Server
Now you can connect without a password.
Manual Key Copy
If ssh-copy-id isn't available:
SSH Config File
Create ~/.ssh/config for shortcuts:
Host prod
HostName 192.168.1.100
User deploy
Port 22
Host staging
HostName 192.168.1.101
User deploy
IdentityFile ~/.ssh/staging_key
Now connect with just:
SSH Config is Powerful
No more remembering IPs, usernames, and ports. Define once in config, use shortcuts forever.
Running Remote Commands
Copying Files: scp
SSH Tunneling (Port Forwarding)
Access a remote service through SSH:
What's the advantage of SSH keys over passwords?
Quick Reference
| Command | Purpose |
|---|---|
ssh user@host | Connect to server |
ssh -p port user@host | Connect on specific port |
ssh-keygen -t ed25519 | Generate SSH key |
ssh-copy-id user@host | Copy key to server |
scp file user@host:path | Copy file to server |
scp user@host:path file | Copy file from server |
Key Takeaways
ssh user@hostconnects to servers- Keys are more secure than passwords
- Use
ssh-keygento create keys ~/.ssh/configsaves time with shortcutsscpcopies files over SSH- SSH is the foundation of remote server work
Congratulations! You've completed Chapter 9: Networking Basics.
Next chapter: Package Management - installing and managing software.