Linux & Windows Server Hardening
Server hardening means shrinking your attack surfaceโturning off what you don't need, locking down remote logins, and encrypting disksโso one mistake doesn't hand over the whole machine.
Defense-in-Depth: If an attacker slips past the network firewall, OS confinement, strong auth, and disk encryption still stop them.
01 Linux SSH & OS Hardening
The #1 way fresh Linux cloud servers get compromised is weak SSH settings and unpatched packages.
Lock down /etc/ssh/sshd_config, ban brute-force bots with fail2ban, and
automate security patches.
PermitRootLogin no
/etc/ssh/sshd_config. Real-world: Forces admins to log in as a normal user first and use sudo, stopping 24/7 root bot attacks.PasswordAuthentication no
sudo sshd -t && sudo systemctl reload ssh
sshd on RHEL/AlmaLinux).sudo apt install -y fail2ban && sudo systemctl enable --now fail2ban
sudo fail2ban-client status sshd.sudo apt install -y unattended-upgrades && sudo dpkg-reconfigure -plow unattended-upgrades
dnf-automatic.02 Linux Auditing & MAC (AppArmor vs SELinux)
Auditing records who changed what on your server. MAC (Mandatory Access Control)
puts strict guardrails on appsโso even if Nginx or Apache gets hacked, it can't read /etc/shadow.
sudo auditctl -w /etc/passwd -p wa -k user_changes
auditd/etc/passwd under the search key user_changes.sudo ausearch -k user_changes -ts today
/var/log/audit/audit.log for today's events tagged user_changes. Great for spotting unauthorized account creation.sudo lynis audit system
getenforce
Enforcing (blocking + logging), Permissive (logging only), or Disabled. Use sudo aa-status on Ubuntu for AppArmor.| Feature | AppArmor | SELinux |
|---|---|---|
| Default Distros | Ubuntu, Debian, SUSE | RHEL, Rocky, AlmaLinux, Fedora |
| How It Confines | File paths (e.g., /usr/sbin/nginx) |
Security labels on every file & process |
| Check Status | sudo aa-status |
getenforce / sestatus |
| Beginner Difficulty | Easier | Stricter / Granular |
AppArmor = "App Paths" (Debian/Ubuntu uses readable file paths). SELinux = "Security Labels" (Red Hat tags every file and process like a VIP badgeโif your badge doesn't match, access is denied).
03 Windows Server Hardening (PowerShell & CLI)
Windows Server hardening focuses on stopping ransomware lateral movement: encrypt drives with BitLocker, rotate local admin passwords with Windows LAPS, kill legacy SMBv1, and keep Defender & UAC active.
manage-bde -status
manage-bde -on C: -RecoveryPassword (always back up the 48-digit recovery key!).Get-LapsADPassword -Identity "SRV-01"
Disable-WindowsOptionalFeature -Online -FeatureName SMB1Protocol -NoRestart
Get-SmbServerConfiguration | Select EnableSMB1Protocol.Get-MpComputerStatus | Select AntivirusEnabled, RealTimeProtectionEnabled
True.Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name EnableLUA
EnableLUA : 1 means UAC is active, preventing silent background apps from elevating to Administrator without a prompt.04 CIS Top 10 Baseline Checklist
The Center for Internet Security (CIS) benchmarks are the gold-standard checklist used by auditors and cloud teams. Start with these 10 high-impact controls on every Linux or Windows server.
| # | Control | Linux Implementation | Windows Implementation |
|---|---|---|---|
| 01 | Least Privilege | No direct root SSH; scoped sudoers |
Standard user + UAC; separate Admin accounts |
| 02 | MFA Everywhere | SSH keys + PAM MFA for jump hosts | Entra ID / AD MFA for RDP & admin portals |
| 03 | Automated Patching | unattended-upgrades / dnf-automatic |
WSUS / Windows Update for Business |
| 04 | Centralized Logging | auditd + rsyslog to SIEM |
Windows Event Forwarding (WEF) to SIEM |
| 05 | Disk Encryption | LUKS full-disk encryption | BitLocker (manage-bde) + TPM |
| 06 | Host Firewall | ufw / nftables / firewalld |
Windows Defender Firewall (Domain/Public/Private) |
| 07 | Disable Legacy Protocols | Remove Telnet, FTP, TLS 1.0/1.1 | Disable SMBv1, NTLMv1, LLMNR |
| 08 | Unique Admin Creds | Per-user SSH keys (never shared) | Windows LAPS for local Administrator |
| 09 | Endpoint / MAC Defense | AppArmor or SELinux Enforcing |
Defender AV + Attack Surface Reduction (ASR) |
| 10 | Tested Backups | Encrypted offline/immutable snapshots | VSS + offline/immutable backup + restore drill |
05 Danger Zone & Quick-Copy Baseline
Hardening mistakes can lock you out of production or silently leave security wide open. Avoid these three classic traps:
PasswordAuthentication no before testing your SSH key
If your public key isn't in ~/.ssh/authorized_keys with 600 permissions, reloading SSH locks you out immediately. Always keep one active root/sudo terminal open while testing a second SSH key session.
setenforce 0 and leaving SELinux in Permissive mode in prod
setenforce 0 is great for 5 minutes of troubleshooting, but leaving it off disables kernel confinement permanently. Fix the policy or file context with restorecon -Rv and switch back to setenforce 1.
A BIOS/TPM firmware update can trigger BitLocker recovery on reboot. Without the recovery key escrowed in AD/Entra ID or a password vault, your server data is permanently unreadable.
sudo sshd -t # 1. Verify SSH config syntax has zero errors sudo systemctl status fail2ban --no-pager # 2. Confirm brute-force protection is active sudo lynis audit system --quick # 3. Run non-interactive hardening audit