Production-grade Ubuntu 22.04 LTS server hardening β automated, modular, and CIS-benchmark aligned.
From a fresh server to hardened, monitored, and compliant in under 5 minutes.
What's New Β· Features Β· Quick Start Β· Modules Β· Scoring Β· Reports
| v2.0 (Previous) | v3.0 (Current) |
|---|---|
| Single monolithic script | Modular β run any module independently |
| SSH + UFW + Fail2Ban + AppArmor + Kernel | + AIDE IDS, rootkit scanner, 2FA, CIS benchmark |
| Basic 8-test suite | 25-test suite with A+/A/B/C grading |
| No rollback | Full rollback/restore for every module |
| No reporting | HTML + JSON reports with score breakdown |
| Manual config only | Interactive setup wizard |
| No scheduling | Cron-based weekly re-audit + email alerts |
| Module | What It Does | Standard |
|---|---|---|
| π SSH Hardening | Port 2222, keys only, rate limiting, banner | CIS 5.2 |
| π‘οΈ UFW Firewall | Default deny, allowlist only, logging | CIS 3.5 |
| π« Fail2Ban | Brute-force protection, auto IP ban | CIS 5.3 |
| π¦ AppArmor | Mandatory access control, SSH confinement | CIS 1.7 |
| 𧬠Kernel Hardening | Sysctl tuning, ASLR, pointer restriction | CIS 3.1 |
| π Auto Updates | Unattended security patch install | CIS 1.9 |
| π AIDE IDS (NEW) | File integrity monitoring β detects tampering | CIS 1.4 |
| π¦ Rootkit Scanner (NEW) | rkhunter + chkrootkit daily scans | CIS 1.3 |
| π 2FA / MFA (NEW) | Google Authenticator TOTP for SSH login | NIST 800-53 |
| π CIS Benchmark (NEW) | 50-point compliance check | CIS Level 1 |
| π HTML Reports (NEW) | Auto-generated security report with scoring | Custom |
| βͺ Rollback (NEW) | Safely undo any hardening change | Custom |
| π Email Alerts (NEW) | Weekly audit + alert on score drop | Custom |
linux-server-hardening/
βββ harden-server.sh # Main script β runs all modules
βββ rollback.sh # NEW: Safely undo hardening
βββ audit.sh # NEW: Weekly re-audit + alerts
βββ status.sh # Live security dashboard
β
βββ scripts/
β βββ 01_system_update.sh # System updates & prereqs
β βββ 02_user_hardening.sh # Secure admin user setup
β βββ 03_ssh_hardening.sh # SSH configuration
β βββ 04_firewall.sh # UFW + Fail2Ban
β βββ 05_apparmor.sh # AppArmor MAC
β βββ 06_kernel_hardening.sh # Sysctl hardening
β βββ 07_auto_updates.sh # Unattended upgrades
β βββ 08_aide_ids.sh # NEW: AIDE file integrity
β βββ 09_rootkit_scanner.sh # NEW: rkhunter + chkrootkit
β βββ 10_two_factor_auth.sh # NEW: Google Authenticator 2FA
β βββ 11_cis_benchmark.sh # NEW: CIS compliance check
β
βββ configs/
β βββ sshd_config.hardened # SSH config template
β βββ fail2ban-jail.local # Fail2Ban config
β βββ sysctl-hardening.conf # Kernel parameters
β βββ aide.conf # AIDE monitoring config
β βββ audit.rules # Auditd rules
β
βββ reports/
β βββ generate_report.sh # NEW: HTML report generator
β βββ Hardening-Report.md # Sample filled report
β βββ cis-benchmark-results.md # CIS check output
β
βββ docs/
β βββ audit-report.md
β βββ client-ssh-config.md
β βββ cis-benchmark-mapping.md # NEW: Full CIS control mapping
β βββ rollback-guide.md # NEW: Rollback documentation
β
βββ tests/
β βββ test-hardening.sh # 25-test verification suite
β
βββ .github/workflows/
βββ test.yml # CI pipeline
- Ubuntu 22.04 LTS (fresh install recommended)
- Root or sudo access
git clone https://github.com/AjayKalbhile/linux-server-hardening.git
cd linux-server-hardening
chmod +x *.sh scripts/*.sh tests/*.sh reports/*.sh
sudo ./harden-server.shsudo ./harden-server.sh --interactiveWizard prompts: admin username, which modules, SSH port, email for alerts.
sudo ./scripts/08_aide_ids.sh # File integrity only
sudo ./scripts/09_rootkit_scanner.sh # Rootkit scan only
sudo ./scripts/10_two_factor_auth.sh # 2FA only
sudo ./scripts/11_cis_benchmark.sh # CIS check onlysudo ./rollback.sh --all # Undo everything
sudo ./rollback.sh --module ssh # Undo only SSH changes
sudo ./rollback.sh --module firewall # Undo only firewallAIDE creates a cryptographic database of your filesystem and alerts you when files are tampered with β detecting rootkits, unauthorized changes, and supply chain attacks.
sudo ./scripts/08_aide_ids.sh
# Manual integrity check
sudo aide --checkMonitors: /etc/, /bin/, /sbin/, /usr/bin/, /boot/, SSH authorized_keys
Runs rkhunter and chkrootkit on a daily cron schedule, cross-checking against known rootkit signatures.
sudo ./scripts/09_rootkit_scanner.sh
# Manual scan
sudo rkhunter --check --sk
sudo chkrootkitAdds TOTP-based 2FA to SSH. Even with a valid SSH key, users also enter a 6-digit TOTP code from Google Authenticator or Authy.
sudo ./scripts/10_two_factor_auth.sh
# Per-user setup
google-authenticator # Scan QR code with your authenticator appRuns 50 automated checks against the CIS Ubuntu 22.04 Level 1 Benchmark and scores your server.
sudo ./scripts/11_cis_benchmark.shSample output:
CIS Ubuntu 22.04 Benchmark β Level 1
ββββββββββββββββββββββββββββββββββββββββββ
[PASS] 1.1.1 Disable mounting of cramfs
[PASS] 1.4.1 AIDE is installed
[PASS] 3.5.1 UFW is installed and active
[PASS] 5.2.4 SSH root login disabled
[FAIL] 1.6.1 Core dumps are restricted
...
Score: 47/50 (94%) β PASS
| Framework | Max | Typical Result |
|---|---|---|
| Lynis Hardening Index | 100 | 98 |
| CIS Ubuntu Benchmark | 50 controls | 47β50 |
| Internal Test Suite | 25 tests | 25/25 |
| Overall Grade | A+ | A+ |
Grade scale: A+ (95β100%) Β· A (85β94%) Β· B (70β84%) Β· C (<70%)
# Generate HTML report
sudo ./reports/generate_report.sh
# β /var/log/hardening/report_YYYYMMDD.html
# Generate JSON report (for SIEM)
sudo ./reports/generate_report.sh --format jsonReport includes: score breakdown, CIS results, AIDE status, Fail2Ban bans, remediation steps.
sudo ./audit.sh --setup-cron --email your@email.comWeekly cron: re-runs test suite, rkhunter scan, AIDE check, emails results if score drops.
sudo ./tests/test-hardening.shπ§ͺ HARDENING VERIFICATION SUITE v3.0
ββββββββββββββββββββββββββββββββββββββββββ
[SSH]
β
SSH on port 2222 β
Root login disabled
β
Password auth disabled β
PubkeyAuthentication enabled
β
LoginGraceTime 30s β
MaxAuthTries 3
β
X11Forwarding disabled β
SSH banner configured
[FIREWALL]
β
UFW active β
Default deny incoming
β
Only approved ports open β
Logging enabled
[SERVICES]
β
Fail2Ban running β
AppArmor enforcing
β
auditd running β
rkhunter installed
β
AIDE initialized
[KERNEL]
β
ASLR enabled β
Kernel pointer restriction
β
SYN cookie protection β
ICMP redirects disabled
β
Source routing disabled
[USERS & ACCOUNTS]
β
Root password locked β
No empty passwords
β
Auto-updates configured
ββββββββββββββββββββββββββββββββββββββββββ
π RESULTS: 25/25 PASSED (100%)
π GRADE: A+ β Server fully hardened!
Test in a non-production environment first. Always backup before running. Authors accept no liability for misconfiguration or downtime.
MIT License β see LICENSE for full details.
Built for the blue team β€οΈ Β· β Star this repo if it helped!