System Setup
Overview
Base system configuration for all infrastructure containers, including SSH hardening, firewall configuration, and security measures.
Common Role
The common Ansible role provides base system configuration for all containers.
Features
- SSH Hardening
- Key-only authentication (password auth disabled)
- Secure SSH configuration
-
Authorized keys management
-
UFW Firewall
- Default incoming: DENY
- Default outgoing: ALLOW
- Allowed ports: 22 (SSH), 80 (HTTP), 443 (HTTPS)
-
MongoDB port: Restricted to internal network only
-
fail2ban
- Brute force protection
- SSH protection
-
Configurable ban times
-
Base Packages
- Essential system packages
- Security updates
- System utilities
SSH Configuration
Key-Only Authentication
Configuration (infra/proxmox/ansible/roles/common/templates/sshd_config.j2):
PasswordAuthentication no
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
SSH Key Management
Current Status: SSH public keys configured in inventory/group_vars/all.yml
Recommendations: - Keep personal SSH keys out of repository - Use environment variables or external files for team keys - Rotate SSH keys regularly
Firewall Configuration
UFW Rules
Default Rules:
# Default policies
ufw default deny incoming
ufw default allow outgoing
# Allow SSH
ufw allow 22/tcp
# Allow HTTP/HTTPS
ufw allow 80/tcp
ufw allow 443/tcp
# MongoDB (internal only)
ufw allow from 10.20.0.0/24 to any port 27017
Firewall Management
# Check firewall status
ufw status
# Enable firewall
ufw enable
# Disable firewall (not recommended)
ufw disable
# View firewall rules
ufw status verbose
fail2ban Configuration
Protection
Enabled on: All servers
Protected services: SSH
Default ban time: Based on Debian defaults
Configuration
Template (infra/proxmox/ansible/roles/common/templates/jail.local.j2):
[sshd]
enabled = true
port = 22
filter = sshd
logpath = /var/log/auth.log
maxretry = 5
bantime = 3600
Management
# Check fail2ban status
systemctl status fail2ban
# View banned IPs
fail2ban-client status sshd
# Unban IP
fail2ban-client set sshd unbanip <IP_ADDRESS>
Base Packages
Installed Packages
curl- HTTP clientwget- File downloadergit- Version controlvim- Text editorhtop- Process monitorjq- JSON processorunzip- Archive utility
Package Updates
# Update package lists
apt update
# Upgrade packages
apt upgrade -y
# Or via Ansible
ansible all -m apt -a "update_cache=yes upgrade=dist" --become
Security Best Practices
SSH Security
- Use Strong Keys: 4096-bit RSA or Ed25519 keys
- Disable Root Login: Use sudo instead
- Limit Access: Restrict SSH to specific IPs if possible
- Regular Rotation: Rotate SSH keys periodically
Firewall Security
- Minimal Ports: Only open necessary ports
- Internal Restrictions: Restrict sensitive ports to internal network
- Regular Review: Review firewall rules periodically
System Security
- Regular Updates: Keep system packages updated
- Monitor Logs: Review system logs regularly
- Fail2ban: Monitor and adjust fail2ban settings
- Audit: Regular security audits
Troubleshooting
SSH Connection Issues
Symptoms: Cannot connect via SSH
Solution:
# Check SSH service
systemctl status sshd
# Check firewall
ufw status
# Check SSH configuration
cat /etc/ssh/sshd_config | grep -E "PasswordAuthentication|PubkeyAuthentication"
# Test SSH connection
ssh -v user@host
Firewall Blocking Services
Symptoms: Services not accessible
Solution:
# Check firewall rules
ufw status verbose
# Check if service is listening
netstat -tulpn | grep <PORT>
# Add firewall rule if needed
ufw allow <PORT>/tcp
fail2ban Issues
Symptoms: Legitimate users blocked
Solution:
# Check banned IPs
fail2ban-client status sshd
# Unban IP
fail2ban-client set sshd unbanip <IP_ADDRESS>
# Adjust fail2ban configuration
# Edit /etc/fail2ban/jail.local
Related Documentation
- Ansible Configuration - Ansible role management
- Authentication - Authentication details
- Terraform Configuration - Infrastructure setup
Last Updated: 2025-12-07