Skip to content

AndyHS-506/Ubuntu-Hardening

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 

Repository files navigation

Ubuntu-Hardening

πŸ”’ Ubuntu 24.04 Hardening Script (CIS Level 1 - Modular)

This project provides an automated Bash script to harden Ubuntu 24.04 LTS systems based on the CIS Benchmark Level 1 - Server Profile. The script is modular, logs every section and command, and enforces security best practices from the ground up.


βœ… Features

  • Implements CIS Level 1 server recommendations
  • Modular sectioned logging with success/error tracking
  • Removes unnecessary packages and services
  • Hardens kernel, network, and SSH settings
  • Enforces password policies and account protections
  • Secures logging and auditing with auditd, rsyslog, acct
  • Configures UFW firewall with sane defaults
  • Verifies critical mount points and partitions

πŸ“‹ Compliance Summary (CIS Ubuntu 24.04 Level 1) 100% (un-comment the password complexity before running to reach 100%)

CIS ID Control Status
1.1.x Disable unused filesystems βœ… Implemented
1.1.1 - 1.1.24 Check separate partitions (/home, /var, etc.) βœ… Verified
1.2.x Secure bootloader (GRUB permissions) βœ… Hardened
1.3.x Enable AppArmor βœ… Enforced
1.4.x Kernel security settings (ASLR, core dumps) βœ… Applied
1.5.x Software updates and unattended-upgrades βœ… Enabled
1.6.x Legal banners (/etc/issue, /etc/motd) βœ… Set
1.7.x Remove GUI login (GDM) βœ… Removed
2.1.x Remove unused services (e.g., FTP, RPC, etc.) βœ… Purged
2.2.x Remove X Window System βœ… Removed
2.3.x Disable Avahi, Autofs βœ… Disabled
2.4.x NTP with systemd-timesyncd βœ… Configured
2.5.x Secure cron and at βœ… Hardened
3.x Network stack hardening and IPv6 disable βœ… Done
4.x UFW Firewall with sane defaults βœ… Enabled
5.1.x SSH configuration hardening βœ… Hardened
5.2.x Secure sudo configuration βœ… Enforced
5.4.x Password policy (age, complexity, reuse, umask) βœ… Enforced
5.5.x Account auditing and UID 0 checks βœ… Audited
6.1.x auditd logging and audit rules βœ… Comprehensive
6.2.x Enable and secure rsyslog βœ… Done
6.3.x Log rotation and journald settings βœ… Configured
6.4.x Enable acct and process tracking βœ… Enabled
6.5.x Secure /etc/passwd, /etc/shadow, etc. βœ… Permissioned

πŸ“‹ CIS Benchmark Coverage (Level 2 - Ubuntu 24.04) 90% (the log will indicate the partition information but it is not possible to auto-fix this as this can change for every installation, hence I prefered to be a manual work) and AppArmor recommendations is set on complain to avoid brasking the system, the change for each profile has to be manual depending on the apps installed)

Section Control Status
1.1.x Filesystem: Remove & restrict unused FS βœ… Done
1.1.1–1.1.24 Mount options + partitions for /tmp, /var, etc. ⚠️ Partially Done
1.2.x Secure GRUB & permissions βœ… Hardened
1.3.x AppArmor in enforce mode ⚠️ Enforce recommended
1.4.x Kernel hardening (ASLR, ptrace, dumps) βœ… Set
1.5.x Update settings and unattended upgrades βœ… Enabled
1.6.x Login banner + permissions βœ… Compliant
1.7–1.8 Remove X/GDM βœ… Removed
2.x Disable unused services βœ… Extensive
3.x Disable uncommon kernel modules, IPv6, redirects βœ… Done
4.x Enable firewall (UFW) βœ… Enabled
5.1.x Secure SSH server configuration βœ… Hardened
5.2.x Secure sudo policy (logging, timeouts) βœ… Compliant
5.4.x Password aging, complexity, reuse βœ… Enforced
5.5.x Disable empty or legacy accounts βœ… Done
6.1.x Enable and configure auditd βœ… Full ruleset
6.2.x Configure rsyslog βœ… Enabled
6.3.x Setup logrotate, persistent journald βœ… Set
6.4.x Enable acct and process auditing βœ… Enabled
6.5.x Secure critical files (/etc/shadow, etc.) βœ… Permissioned

⚠️ Disclaimer This script applies system-level changes. Use with caution in production. Always test in a staging environment first. This project is provided "as is" and is not affiliated with the Center for Internet Security (CIS).

πŸ§ͺ Tested On -βœ… Ubuntu 24.04 LTS (Server) -πŸ§ͺ LXC, KVM, bare-metal and cloud VMs

  • 🧰 Compatible with Proxmox, VMware, Hyper-V, Oracle Cloud, and more

πŸ“‚ Directory Structure

/home/<user>/setup_logs/hardening.log/
β”œβ”€β”€ main.log                 # High-level section logs
└── section_logs/
    β”œβ”€β”€ <section_id>/
        β”œβ”€β”€ success.log
        β”œβ”€β”€ error.log
        └── details.log


About

Ubuntu 24.04 CIS Benchmark Hardening Script

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages