Skip to content

About

Automated Ubuntu 22.04 LTS server hardening - 100% test coverage

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

Β 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›‘οΈ Linux Server Hardening Toolkit v3.0


Bash Ubuntu Lynis License CIS Status


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



πŸ†• What's New in v3.0

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

✨ Features

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

πŸ—οΈ Project Structure

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

πŸš€ Quick Start

Prerequisites

  • Ubuntu 22.04 LTS (fresh install recommended)
  • Root or sudo access

Option A β€” Full Hardening (All Modules)

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.sh

Option B β€” Interactive Wizard

sudo ./harden-server.sh --interactive

Wizard prompts: admin username, which modules, SSH port, email for alerts.

Option C β€” Run a Single Module

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 only

Option D β€” Rollback

sudo ./rollback.sh --all               # Undo everything
sudo ./rollback.sh --module ssh        # Undo only SSH changes
sudo ./rollback.sh --module firewall   # Undo only firewall

πŸ”§ Hardening Modules (NEW in v3.0)

Module 8 β€” AIDE File Integrity Monitoring

AIDE 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 --check

Monitors: /etc/, /bin/, /sbin/, /usr/bin/, /boot/, SSH authorized_keys


Module 9 β€” Rootkit Scanner

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 chkrootkit

Module 10 β€” Two-Factor Authentication (2FA)

Adds 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 app

Module 11 β€” CIS Benchmark Compliance

Runs 50 automated checks against the CIS Ubuntu 22.04 Level 1 Benchmark and scores your server.

sudo ./scripts/11_cis_benchmark.sh

Sample 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

πŸ“Š Security Scoring

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%)


πŸ“‹ Reports

# 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 json

Report includes: score breakdown, CIS results, AIDE status, Fail2Ban bans, remediation steps.


πŸ”” Automated Weekly Audit

sudo ./audit.sh --setup-cron --email your@email.com

Weekly cron: re-runs test suite, rkhunter scan, AIDE check, emails results if score drops.


πŸ§ͺ Verification Suite β€” 25 Tests

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!

⚠️ Disclaimer

Test in a non-production environment first. Always backup before running. Authors accept no liability for misconfiguration or downtime.


πŸ“„ License

MIT License β€” see LICENSE for full details.


Built for the blue team ❀️ · ⭐ Star this repo if it helped!

About

Automated Ubuntu 22.04 LTS server hardening - 100% test coverage

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages