A lightweight, automated Bash script designed to apply baseline security hardening to newly provisioned Linux servers. Supports both RHEL/Fedora and Debian/Ubuntu environments.
- OS Detection: Automatically identifies package manager and system architecture (
aptvsdnf/yum). - Service Minimisation: Identifies, stops, and disables legacy or insecure services (
telnet,vsftpd,cups, etc.). - SSH Hardening:
- Backs up existing
sshd_configwith a timestamp before making edits. - Disables direct
rootlogin. - Disables password authentication (enforces SSH keys).
- Disables empty passwords.
- Backs up existing
- Automated Firewall Baseline:
- Configures UFW on Debian/Ubuntu (Deny Incoming, Allow Outgoing, Allow SSH).
- Configures Firewalld on RHEL/Fedora derivatives (Sets default zone to
drop, opens SSH).
- Audit Logging: Logs all terminal output, warnings, and changes to
/var/log/system_hardening_<date>.log.
⚠️ Warning: This script disables SSH password authentication. Ensure you have valid SSH key access configured before running this script to avoid locking yourself out of your server.
git clone https://github.com/SudoShea/linux-system-hardening.git
cd linux-system-hardeningchmod +x harden.shsudo ./harden.sh[+] Starting system hardening script. Logging to /var/log/system_hardening_2026-07-23_16:00:00.log
[+] Detected Operating System: fedora
[+] Phase 1: Disabling insecure and unused services...
[+] Phase 2: Securing SSH configuration...
[+] Backed up sshd_config to /etc/ssh/sshd_config.bak_2026-07-23_16:00:00
[+] SSH configuration updated and service restarted.
[+] Phase 3: Configuring Firewall...
[+] Setting up Firewalld (RHEL/Fedora)...
[+] Firewalld enabled and set to drop all incoming except SSH.
==============================================================================
Hardening Complete!
==============================================================================
Distributed under the MIT License. See LICENSE for details.