Security Basics
Your server is on the internet. Attackers are scanning it right now. Let's make their job harder.
The Attacker's Perspective
What they try first:
- SSH brute force (root / common passwords)
- Scan for open ports with vulnerable services
- Exploit known vulnerabilities in outdated software
- Attack web applications
SSH Security
Disable Root Login
PermitRootLogin no
Use SSH Keys Only
PasswordAuthentication no
PubkeyAuthentication yes
Change Default Port (Optional)
Port 2222
Don't forget to update your firewall:
Test Before Disconnecting
After SSH changes, open a new terminal and test the connection before closing your current session.
Firewall with UFW
Allow Specific IPs
Keep Software Updated
fail2ban - Block Brute Force
Custom configuration:
[sshd]
enabled = true
port = ssh
maxretry = 3
bantime = 1h
findtime = 10m
File Permissions
Principle of Least Privilege
- Don't run services as root
- Create dedicated service users
- Use sudo instead of root shell
- Grant minimum required permissions
# Bad: running app as root
sudo node server.js
# Good: dedicated user
sudo -u appuser node server.js
# Better: systemd service as non-root
# In service file: User=appuser
Monitor Your System
Check Login Attempts
Check Open Ports
If you see unexpected ports, investigate.
Security Checklist
□ SSH: Key auth only, root disabled
□ Firewall enabled, minimal ports open
□ Automatic security updates
□ fail2ban protecting SSH
□ Services running as non-root
□ Regular backups
□ Monitoring for anomalies
□ Strong passwords where needed
□ Software kept updated
Why should you disable password authentication for SSH?
Quick Reference
| Action | Command |
|---|---|
| Check open ports | sudo ss -tulpn |
| Check firewall | sudo ufw status |
| Check failed logins | grep 'Failed' /var/log/auth.log |
| Check banned IPs | sudo fail2ban-client status sshd |
| Update system | sudo apt update && sudo apt upgrade |
| Check running services | systemctl list-units --type=service |
Key Takeaways
- SSH: keys only, no root, consider changing port
- Firewall: default deny, allow only what's needed
- Keep software updated (automatic is good)
- fail2ban blocks brute force attacks
- Run services as non-root users
- Monitor logs for suspicious activity
- Security is ongoing, not a one-time setup
Next: where to go from here.