Ubuntu Security Hardening
Ubuntu Security Hardening Guide for 2026
Ubuntu is one of the most popular Linux distributions for servers and desktops, but default installations are not fully secure. Properly hardening your Ubuntu systems in 2026 is essential for both homelab and production environments.
This guide covers the most important and practical security hardening steps.
Why Hardening Matters
Reduced Attack Surface
Protection Against Automated Attacks
Improved System Resilience
Essential Security Hardening Steps
Keep the System Updated
sudo apt update && sudo apt upgrade -y
sudo apt install unattended-upgrades -y
sudo dpkg-reconfigure unattended-upgrades
Configure the Firewall (UFW)
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
Harden SSH Access
sudo nano /etc/ssh/sshd_config
# Recommended settings:
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
sudo systemctl restart ssh
Install and Configure Fail2Ban
sudo apt install fail2ban -y
sudo systemctl enable --now fail2ban
Enable AppArmor (Default on Ubuntu)
sudo apt install apparmor apparmor-utils -y
sudo systemctl enable --now apparmor
sudo aa-status
Create a Non-Root User
sudo adduser yourusername
sudo usermod -aG sudo yourusername
Kernel Parameter Hardening (sysctl)
kernel.kptr_restrict = 2
kernel.dmesg_restrict = 1
kernel.unprivileged_userns_clone = 0
kernel.yama.ptrace_scope = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.tcp_syncookies = 1
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
sudo sysctl -p /etc/sysctl.d/99-security.conf
Advanced: SELinux on Ubuntu
SELinux vs AppArmor
When to Consider SELinux
Basic SELinux Installation on Ubuntu
sudo apt install selinux-basics selinux-policy-default auditd -y
sudo selinux-activate
sudo setenforce 1
Additional Recommendations
Enable Automatic Reboots After Updates
Regular Security Auditing
Implement a Backup Strategy
Questions for the Community
What hardening steps do you use?
AppArmor vs SELinux
Biggest Lesson
Disclaimer
This content is for educational and informational purposes only. It is not technical advice. Always test security configurations thoroughly in your own environment before applying them to production systems.
DISCUSSION
No replies yet. Be the first to join the discussion!