!!-- Consider this broken as of now it will be going an overhaul soon --!!
!!-- DO NOT USE ON A PRODUCTION MACHINE --!!
FORTRESS.SH :: Debian Linux Defence Configuration
NOTICE: Fix Permissions .sh was causing issues on some systems it's been removed for now, the newer versions should already have fixed the issues that script attempted to.
One-command security hardening that implements enterprise-grade protections (DISA STIG + CIS) while letting you decide the level of protection vs usability trade-off. Casual desktop use through to strict server enforcement.
Version 5.3 — Container/Turnkey LXC compatibility. The script no longer hard-requires the sudo binary, so it runs cleanly on Turnkey Linux LXC and other minimal root containers where sudo isn't installed. Everything from v5.2 (the -x/--disable fix, --scanner-mode, CLI/config precedence, sftp-server detection) is unchanged. Tested on Debian 13, Ubuntu 24.04+, and Turnkey Core LXC.
CRITICAL WARNING FOR REMOTE SERVER USERS
Set up SSH keys FIRST or you WILL be locked out.
v5.3 keeps all the safety checks from v5.1/v5.2 (explicit "yes" confirmation, automatic config validation, rollback on sshd syntax error) but you still need working key-based authentication before running the script. See Critical Warning for Remote Servers for full setup instructions.
Notice
This script handles network/system hardening, AppArmor (not SELinux), audit logging and other security features. It does NOT do user group management, SELinux, or touch VFIO/IOMMU configs. Handle those separately before or after running the script.
Quick Start
Note on sudo: every example below uses sudo ./fortress_improved.sh because that's the common case. If you're on a Turnkey LXC container (or any environment where you're already root and sudo isn't installed) just drop the sudo — ./fortress_improved.sh works the same way. The script detects this at startup and won't complain.
Desktop Users:
# Download and make executable
wget https://raw.githubusercontent.com/captainzero93/security_harden_linux/main/fortress_improved.sh
chmod +x fortress_improved.sh
# Learn what it does (recommended first time)
sudo ./fortress_improved.sh --explain --dry-run
# Apply with defaults
sudo ./fortress_improved.sh
# Answer the interactive prompts, then reboot when done
Server Users:
# FIRST: Set up SSH keys (CRITICAL - see full warning below)
ssh-keygen -t ed25519
ssh-copy-id user@your-server
# Then run hardening
sudo ./fortress_improved.sh -l high -n
Turnkey LXC / Root Containers:
# Already root, no sudo binary - just run it directly
wget https://raw.githubusercontent.com/captainzero93/security_harden_linux/main/fortress_improved.sh
chmod +x fortress_improved.sh
./fortress_improved.sh -l moderate
Something broke? Restore from backup directory: /root/fortress_backups_*/
Table of Contents
Your Fresh Linux Install Isn't Secure
Ubuntu, Fedora, Mint, Kubuntu - they all ship with security settings that prioritise "making things work" over "keeping you safe." This is intentional. Distributions assume you'll configure security later.
But most people never do.
Right now, your system likely has: no firewall enabled so any service you run is exposed to the internet, SSH ports wide open to brute force bots trying thousands of passwords per hour, no tracking of failed login attempts giving attackers unlimited tries, no automatic security updates meaning you could be vulnerable for weeks, minimal kernel protections making exploits easier, and no intrusion detection so if someone breaks in you won't know.
This isn't a Linux flaw - it's a conscious trade-off. Distributions prioritise compatibility and ease-of-use for new users. Great for getting started, terrible for security.
Who This Is For
You, if you: game on Linux and want security without FPS loss, create art/music/videos without security getting in the way, work from home and need basic protection, just want a secure personal computer that works normally, are tired of complicated security guides written for sysadmins, run a home server or self-host services, develop software and want security without breaking your tools, are learning Linux and want to start with good habits, or want to understand security rather than just blindly apply it.
What makes this different: This script applies industry-standard security WITHOUT breaking your desktop experience. No more choosing between security and usability. v5.1 also intelligently detects Docker and browsers to avoid breaking them.
What This Actually Does
Instead of spending 40+ hours reading security guides and manually configuring dozens of tools, this script handles it in one go.
Security You Get:
- Enables your firewall (UFW) - but keeps Steam, Discord, KDE Connect working
- Hardens SSH - prevents brute force attacks if you use remote access
- Blocks repeated failed logins - optional fail2ban (only if beneficial for your setup)
- Secures the kernel - protection against memory exploits and attacks
- Verifies package integrity - weekly dpkg verification (detects tampering/corruption)
- Enforces strong passwords - because "password123" is still too common
- Enables automatic security updates - patches critical bugs while you sleep
- Configures audit logging - forensics and evidence if something happens
- Verifies boot security - checks Secure Boot status and guides configuration
- Removes unnecessary packages - smaller attack surface
Things That Should Keep Working:
- Steam and all your games (zero/low FPS impact)
- Discord, Zoom, Slack, Teams
- Wacom tablets, drawing tools, pen pressure and tilt
- Audio production (Jack, PipeWire, ALSA) - real-time scheduling preserved
- Video editing (DaVinci Resolve, Kdenlive, OBS) - hardware encoding intact
- Game development (Godot, Unity, Unreal) - build processes unaffected
- Bluetooth audio and devices
- Network printers and file sharing
- KDE Connect phone integration
- USB devices (with optional logging)
- RGB peripherals and gaming gear
- Virtual machines (VirtualBox, QEMU)
- Docker and development tools (v5.1 conditional IP forwarding)
- Firefox, Chrome, Brave browsers (v5.1 smart /dev/shm handling)
Desktop Users: This Won't Ruin Your Workflow
The script detects desktop environments automatically and knows you're not a server. It asks before blocking features like mDNS (network discovery), KDE Connect, and Samba. Gaming functionality is preserved with no/little impact on Steam, Lutris, or Proton. There are no background processes eating CPU/GPU. Audio production, creative tools, and Bluetooth all work as normal. It uses "moderate" security by default (balanced, not paranoid), creates automatic backups before every change, and explains each action in educational mode with the --explain flag.
At "moderate" level (the default), you won't even notice the changes. Your computer will feel exactly the same, just with far fewer security holes.
Critical Warning for Remote Servers
YOU WILL LOCK YOURSELF OUT IF YOU SKIP THIS SECTION
This script disables password authentication for SSH and switches to key-only authentication. This is the single most effective security improvement you can make for SSH. But if you don't have SSH keys set up BEFORE running this script, you will be permanently locked out of your server.
Before Running This Script on ANY Remote Server:
# On your LOCAL machine (laptop/desktop):
ssh-keygen -t ed25519 -C "your_email@example.com"
# Copy the key to your server:
ssh-copy-id username@your-server-ip
# Test that it works:
ssh -i ~/.ssh/id_ed25519 username@your-server-ip
# If you can log in without typing a password, you're good to go
# ONLY THEN run the hardening script on the server
Safety features built into the script: It detects if SSH server is running, requires explicit "yes" confirmation that you have working SSH keys, provides setup instructions if you don't have keys, gives multiple warnings before disabling password auth, validates configuration before applying changes, and auto-rolls back on SSH configuration errors.
If you still lock yourself out: You'll need physical access to the server (or console access from your hosting provider) to restore /etc/ssh/sshd_config from the backup.
For desktop users: If you don't use SSH to remotely access your computer, this doesn't affect you. The script will detect this and handle it appropriately.
Why This Matters - Real-World Attacks
The Brute Force Bot
Without this script, your SSH port (22) is open to the internet. Automated bots try 10,000+ password combinations per hour. Eventually, a weak password gets cracked.
What this script does: Disables password authentication completely (key-only access), optionally changes SSH port, rate limits connection attempts, and offers optional fail2ban for additional services.
Why fail2ban is optional: With password auth disabled and key-only SSH, brute force attacks become impossible. The script intelligently detects this and recommends skipping fail2ban unless you have web/mail servers that benefit from it.
The Kernel Exploit
A vulnerability in the Linux kernel allows attackers to escalate privileges, going from limited user to root access.
What this script does: Enables kernel hardening (sysctl parameters), restricts access to kernel symbols, enables ASLR (Address Space Layout Randomization), and configures memory protections.
The Supply Chain Attack
A compromised package update installs malware. You don't notice until your data is encrypted or stolen.
What this script does: Weekly package integrity verification using dpkg, audit logging for file changes, system file monitoring for tampering, and AppArmor to limit what processes can do.
Note: v5.0 removed AIDE because it can't detect kernel-level rootkits on live systems. dpkg's built-in verification is more appropriate for package integrity checking.
The Physical Access Attack
Someone boots your computer from USB, mounts your drive, and steals everything.
What this script does: Verifies Secure Boot status, provides instructions for enabling Secure Boot in BIOS, sets GRUB bootloader password, restricts boot parameter modification, and secures boot configuration files.
What's New
v5.3 — Container / Turnkey LXC Compatibility
A small, targeted release. v5.2 had a hidden assumption baked into every privileged call — that sudo exists on the system. On a normal Debian/Ubuntu install that's fine, but on Turnkey Linux LXC containers (and a lot of other minimal containers) you log in as root and sudo isn't installed. The script blew up on the first sudo apt-get update with sudo: command not found.
Fixed:
- The
sudo dependency. Every privileged command now goes through a single ${SUDO} wrapper that's resolved once at startup. If you're already root (EUID=0), it's empty and commands run directly. If you're not root but sudo exists, it's set to sudo and the script primes the timestamp once so you don't get prompted twelve times during the run. If neither applies, the script bails out early with a Turnkey-aware error message instead of failing halfway through hardening.
check_permissions() no longer just refuses to run unless you typed sudo — it actually checks what privilege model is available and adapts.
Nothing else changed. All the v5.2 behaviour (-x/--disable semantics, --scanner-mode, CLI vs config precedence, sftp-server probing, kernel.yama.ptrace_scope, the verify script fixes) is unchanged. If v5.2 already worked for you, v5.3 is a drop-in replacement.
Where this matters:
- Turnkey Core / Turnkey Fileserver / Turnkey LXC images
- Proxmox LXC containers built from a minimal Debian template
- Stripped-down Docker containers used for testing the script
- Any chroot or container where you're root and
sudo was never installed
If you're on a normal desktop or server with sudo set up the usual way, you won't notice any difference.
v5.2 - Module Control & Scanner Compatibility
Critical fixes based on user-reported issues:
Fixed:
- Issue #17 —
-x/--disable and -e/--enable silently ignored. The dependency resolver in v5.1 could re-add a module you'd just excluded because another module depended on it. Example: -x firewall,ssh_hardening while leaving fail2ban enabled would still install firewall and ssh_hardening because fail2ban