|
| 1 | +# Ubuntu Server Security |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +Production-ready security configurations for Ubuntu servers. |
| 8 | + |
| 9 | +**The Problem**: Security tools are powerful but complex to configure. Default settings generate noise, integrations are missing, and credentials are stored in plaintext. After weeks of hardening production servers to 100% CIS Benchmark compliance, I've extracted 14 battle-tested security components. |
| 10 | + |
| 11 | +## Components |
| 12 | + |
| 13 | +| Component | Description | |
| 14 | +|-----------|-------------| |
| 15 | +| **[boot-security/](boot-security/)** | GRUB + UEFI password protection (defense-in-depth) | |
| 16 | +| **[kernel-hardening/](kernel-hardening/)** | Kernel security via sysctl parameters + /tmp hardening | |
| 17 | +| **[usb-defense/](usb-defense/)** | 3-layer USB defense system (kernel blacklist + real-time detection + auditd) | |
| 18 | +| **[ssh-hardening/](ssh-hardening/)** | SSH hardening with 15+ CIS Benchmark controls | |
| 19 | +| **[ufw/](ufw/)** | UFW Firewall baseline (CIS-compliant, Docker-aware) | |
| 20 | +| **[nftables/](nftables/)** | Advanced firewall (NAT, Docker, WireGuard VPN, rate-limiting) | |
| 21 | +| **[aide/](aide/)** | Intrusion Detection with 99.7% false-positive reduction | |
| 22 | +| **[rkhunter/](rkhunter/)** | Rootkit detection with automated scanning | |
| 23 | +| **[auditd/](auditd/)** | Kernel-level audit logging (CIS 4.1.x, SIEM-ready) | |
| 24 | +| **[apparmor/](apparmor/)** | Mandatory Access Control profiles (PostgreSQL, Docker) | |
| 25 | +| **[vaultwarden/](vaultwarden/)** | Credential management via Bitwarden CLI (no plaintext secrets) | |
| 26 | +| **[fail2ban/](fail2ban/)** | Brute-force protection (GeoIP filtering, Telegram alerts) | |
| 27 | +| **[security-monitoring/](security-monitoring/)** | Unified security event monitoring with smart deduplication | |
| 28 | +| **[lynis/](lynis/)** | Security auditing & hardening recommendations (CIS compliance) | |
| 29 | + |
| 30 | +## Features |
| 31 | + |
| 32 | +- ✅ **Defense-in-Depth** - 14 complementary security layers (boot → kernel → hardware → network → detection → logging → audit → monitoring) |
| 33 | +- ✅ **CIS Benchmark Compliance** - 40+ controls across all components |
| 34 | +- ✅ **Drop-in Configuration Pattern** - Modular configs for all components |
| 35 | +- ✅ **Docker-Compatible** - All hardening tested with containerized workloads |
| 36 | +- ✅ **Prometheus Integration** - Metrics exporters for monitoring |
| 37 | +- ✅ **systemd Automation** - Daily checks with configurable schedules |
| 38 | +- ✅ **Production-Proven** - Running on multiple Ubuntu servers with 100% CIS compliance |
| 39 | + |
| 40 | +## Quick Start |
| 41 | + |
| 42 | +Each component has its own README with detailed setup instructions. Here's a quick overview: |
| 43 | + |
| 44 | +```bash |
| 45 | +# Clone the repository |
| 46 | +git clone https://github.com/fidpa/ubuntu-server-security.git |
| 47 | +cd ubuntu-server-security |
| 48 | + |
| 49 | +# Choose components based on your needs: |
| 50 | + |
| 51 | +# 1. Boot Security (prevents unauthorized boot modifications) |
| 52 | +sudo ./boot-security/scripts/setup-grub-password.sh |
| 53 | + |
| 54 | +# 2. Kernel Hardening (sysctl + /tmp hardening) |
| 55 | +sudo ./kernel-hardening/scripts/setup-kernel-hardening.sh |
| 56 | + |
| 57 | +# 3. USB Defense (3-layer protection against USB attacks) |
| 58 | +sudo ./usb-defense/scripts/deploy-usb-defense.sh |
| 59 | + |
| 60 | +# 4. SSH Hardening (key-only auth, modern crypto) |
| 61 | +sudo cp ssh-hardening/sshd_config.template /etc/ssh/sshd_config |
| 62 | +./ssh-hardening/scripts/validate-sshd-config.sh |
| 63 | +sudo systemctl restart sshd |
| 64 | + |
| 65 | +# 4. UFW Firewall (simple servers) |
| 66 | +sudo apt install ufw |
| 67 | +sudo ufw default deny incoming |
| 68 | +sudo ufw default allow outgoing |
| 69 | +sudo ufw limit 22/tcp |
| 70 | +sudo ufw enable |
| 71 | + |
| 72 | +# 6. nftables Firewall (gateways, advanced setups) |
| 73 | +sudo cp nftables/drop-ins/20-server.nft.template /etc/nftables.conf |
| 74 | +sudo nftables/scripts/validate-nftables.sh /etc/nftables.conf |
| 75 | +sudo nftables/scripts/deploy-nftables.sh /etc/nftables.conf |
| 76 | + |
| 77 | +# 7. AIDE (intrusion detection) |
| 78 | +sudo apt install aide aide-common |
| 79 | +sudo cp aide/aide.conf.template /etc/aide/aide.conf |
| 80 | +sudo cp aide/drop-ins/*.conf /etc/aide/aide.conf.d/ |
| 81 | +sudo aideinit |
| 82 | + |
| 83 | +# 8. rkhunter (rootkit detection) |
| 84 | +sudo apt install rkhunter |
| 85 | +sudo rkhunter --propupd |
| 86 | +``` |
| 87 | + |
| 88 | +**Full guides**: See each component's `README.md` and `docs/SETUP.md`. |
| 89 | + |
| 90 | +## Component Overview |
| 91 | + |
| 92 | +### Security Layers |
| 93 | + |
| 94 | +| Layer | Component | Purpose | |
| 95 | +|-------|-----------|---------| |
| 96 | +| **Boot** | boot-security | Prevent unauthorized boot modifications | |
| 97 | +| **Kernel** | kernel-hardening | Harden kernel parameters, /tmp isolation | |
| 98 | +| **Hardware** | usb-defense | Block USB-based attacks (3-layer defense) | |
| 99 | +| **Network** | ssh-hardening | Secure remote access | |
| 100 | +| **Firewall** | ufw / nftables | Control network traffic | |
| 101 | +| **Detection** | aide, rkhunter, fail2ban | Detect intrusions and rootkits | |
| 102 | +| **Logging** | auditd | Kernel-level event logging | |
| 103 | +| **Access Control** | apparmor | Mandatory Access Control | |
| 104 | +| **Credentials** | vaultwarden | Eliminate plaintext secrets | |
| 105 | +| **Monitoring** | security-monitoring | Unified security event monitoring | |
| 106 | +| **Audit** | lynis | Comprehensive security auditing | |
| 107 | + |
| 108 | +### Firewall Selection Guide |
| 109 | + |
| 110 | +| Use Case | Component | Why | |
| 111 | +|----------|-----------|-----| |
| 112 | +| Simple server (web, database, NAS) | **UFW** | Easy syntax, CIS-compliant | |
| 113 | +| Gateway / Router | **nftables** | NAT, routing, Multi-WAN | |
| 114 | +| WireGuard VPN server | **nftables** | Native VPN integration | |
| 115 | +| Docker host (simple) | **UFW** | With Docker-aware patterns | |
| 116 | +| Docker host (advanced) | **nftables** | Chain preservation, custom rules | |
| 117 | + |
| 118 | +### Detection & Monitoring Components |
| 119 | + |
| 120 | +| Component | Method | Best For | |
| 121 | +|-----------|--------|----------| |
| 122 | +| **AIDE** | Integrity-based | Detecting file changes | |
| 123 | +| **rkhunter** | Signature-based | Detecting known rootkits | |
| 124 | +| **auditd** | Event-based | Real-time "who did what when" | |
| 125 | +| **fail2ban** | Pattern-based | Blocking brute-force attacks | |
| 126 | +| **security-monitoring** | Aggregation-based | Unified event monitoring with smart deduplication | |
| 127 | +| **Lynis** | Audit-based | Comprehensive security posture assessment | |
| 128 | + |
| 129 | +**Recommendation**: Use all six for defense-in-depth. |
| 130 | + |
| 131 | +## Key Concepts |
| 132 | + |
| 133 | +### Drop-in Configuration Pattern |
| 134 | + |
| 135 | +All components use modular drop-in configurations instead of monolithic files: |
| 136 | + |
| 137 | +``` |
| 138 | +# AIDE drop-ins |
| 139 | +/etc/aide/aide.conf.d/ |
| 140 | +├── 10-docker-excludes.conf |
| 141 | +├── 20-postgresql-excludes.conf |
| 142 | +└── 99-custom.conf |
| 143 | +
|
| 144 | +# nftables drop-ins |
| 145 | +nftables/drop-ins/ |
| 146 | +├── 10-gateway.nft.template |
| 147 | +├── 20-server.nft.template |
| 148 | +└── 40-docker.nft.template |
| 149 | +
|
| 150 | +# UFW drop-ins |
| 151 | +ufw/drop-ins/ |
| 152 | +├── 10-webserver.rules |
| 153 | +├── 20-database.rules |
| 154 | +└── 30-monitoring.rules |
| 155 | +``` |
| 156 | + |
| 157 | +**Benefits**: Easier maintenance, service-specific configs, no merge conflicts. |
| 158 | + |
| 159 | +### CIS Benchmark Alignment |
| 160 | + |
| 161 | +| Component | CIS Controls | |
| 162 | +|-----------|--------------| |
| 163 | +| boot-security | 1.4.x (Boot settings) | |
| 164 | +| kernel-hardening | 1.5.x, 3.2.x (Kernel params) | |
| 165 | +| usb-defense | Physical security (not in CIS, but defense-in-depth) | |
| 166 | +| ssh-hardening | 5.2.x (SSH configuration) | |
| 167 | +| ufw | 3.5.1.x (UFW firewall) | |
| 168 | +| nftables | 3.5.3.x (nftables firewall) | |
| 169 | +| aide | 1.3.x (File integrity) | |
| 170 | +| auditd | 4.1.x (System accounting) | |
| 171 | +| apparmor | 1.6.x (MAC) | |
| 172 | +| lynis | Various (audit all controls) | |
| 173 | + |
| 174 | +## Requirements |
| 175 | + |
| 176 | +**Minimum**: |
| 177 | +- Ubuntu 22.04 LTS or 24.04 LTS (or compatible distro) |
| 178 | +- systemd (for timer automation) |
| 179 | +- Root/sudo access |
| 180 | + |
| 181 | +**Component-specific**: |
| 182 | +- nftables 1.0+ (for advanced firewall features) |
| 183 | +- AIDE v0.18.6+ (for modern hash algorithms) |
| 184 | +- UFW (included in Ubuntu/Debian by default) |
| 185 | + |
| 186 | +**Optional**: |
| 187 | +- Prometheus + node_exporter (for metrics) |
| 188 | +- Vaultwarden/Bitwarden server (for credential management) |
| 189 | + |
| 190 | +## Compatibility |
| 191 | + |
| 192 | +**Fully supported**: |
| 193 | +- Ubuntu 22.04 LTS, 24.04 LTS |
| 194 | +- Debian 11 (Bullseye), 12 (Bookworm) |
| 195 | +- Raspberry Pi OS (Debian-based) |
| 196 | + |
| 197 | +**Partial support** (no AppArmor/UFW components): |
| 198 | +- RHEL / Fedora / Rocky Linux (use SELinux + firewalld instead) |
| 199 | +- Other systemd-based distros (boot-security, kernel-hardening, ssh-hardening, nftables, aide, rkhunter work) |
| 200 | + |
| 201 | +## Use Cases |
| 202 | + |
| 203 | +- ✅ **Enterprise Infrastructure** - Servers, container hosts, network gateways |
| 204 | +- ✅ **Production Servers** - CIS Benchmark compliance with 40+ controls |
| 205 | +- ✅ **Container Hosts** - Docker-compatible hardening (kernel, firewall, AIDE) |
| 206 | +- ✅ **Network Gateways** - nftables with NAT, WireGuard VPN, Multi-WAN |
| 207 | +- ✅ **Compliance** - Generate audit trails and change reports |
| 208 | + |
| 209 | +## Documentation |
| 210 | + |
| 211 | +Each component has its own documentation: |
| 212 | + |
| 213 | +| Component | Key Docs | |
| 214 | +|-----------|----------| |
| 215 | +| boot-security | [GRUB_PASSWORD.md](boot-security/docs/GRUB_PASSWORD.md), [UEFI_PASSWORD.md](boot-security/docs/UEFI_PASSWORD.md) | |
| 216 | +| usb-defense | [THREE_LAYER_DEFENSE.md](usb-defense/docs/THREE_LAYER_DEFENSE.md), [SETUP.md](usb-defense/docs/SETUP.md) | |
| 217 | +| ssh-hardening | [CIS_CONTROLS.md](ssh-hardening/docs/CIS_CONTROLS.md), [SETUP.md](ssh-hardening/docs/SETUP.md) | |
| 218 | +| ufw | [SETUP.md](ufw/docs/SETUP.md), [DOCKER_NETWORKING.md](ufw/docs/DOCKER_NETWORKING.md) | |
| 219 | +| nftables | [SETUP.md](nftables/docs/SETUP.md), [WIREGUARD_INTEGRATION.md](nftables/docs/WIREGUARD_INTEGRATION.md) | |
| 220 | +| aide | [FALSE_POSITIVE_REDUCTION.md](aide/docs/FALSE_POSITIVE_REDUCTION.md) | |
| 221 | +| rkhunter | [FALSE_POSITIVES.md](rkhunter/docs/FALSE_POSITIVES.md) | |
| 222 | +| auditd | [CIS_CONTROLS.md](auditd/docs/CIS_CONTROLS.md), [SETUP.md](auditd/docs/SETUP.md) | |
| 223 | +| lynis | [HARDENING_GUIDE.md](lynis/docs/HARDENING_GUIDE.md), [SETUP.md](lynis/docs/SETUP.md) | |
| 224 | + |
| 225 | +**Repository-level docs**: |
| 226 | + |
| 227 | +| Document | Description | |
| 228 | +|----------|-------------| |
| 229 | +| [docs/SETUP.md](docs/SETUP.md) | General installation guide | |
| 230 | +| [docs/BEST_PRACTICES.md](docs/BEST_PRACTICES.md) | Production lessons | |
| 231 | +| [docs/TROUBLESHOOTING.md](docs/TROUBLESHOOTING.md) | Common issues | |
| 232 | +| [docs/PROMETHEUS_INTEGRATION.md](docs/PROMETHEUS_INTEGRATION.md) | Metrics setup | |
| 233 | + |
| 234 | +## See Also |
| 235 | + |
| 236 | +- [ubuntu-server-security-ansible](https://github.com/fidpa/ubuntu-server-security-ansible) - Ansible automation |
| 237 | +- [monitoring-templates](https://github.com/fidpa/monitoring-templates) - Bash/Python monitoring templates |
| 238 | +- [bash-production-toolkit](https://github.com/fidpa/bash-production-toolkit) - Production-ready Bash libraries |
| 239 | + |
| 240 | +## License |
| 241 | + |
| 242 | +MIT License - see [LICENSE](LICENSE) for details. |
| 243 | + |
| 244 | +## Author |
| 245 | + |
| 246 | +Marc Allgeier ([@fidpa](https://github.com/fidpa)) |
| 247 | + |
| 248 | +**Why I Built This**: After spending weeks hardening production servers to 100% CIS Benchmark compliance, I wished I could find everything in one place. This repo consolidates 14 production-tested security components so you don't have to piece together scattered documentation. |
| 249 | + |
| 250 | +## Contributing |
| 251 | + |
| 252 | +Contributions welcome! Please open an issue or pull request. |
| 253 | + |
| 254 | +**Areas where help is appreciated**: |
| 255 | +- Additional drop-in configs for services (MySQL, Redis, Nginx, etc.) |
| 256 | +- Firewall templates for specific use cases |
| 257 | +- Grafana dashboard examples |
| 258 | +- Testing on other Ubuntu/Debian versions |
0 commit comments