Security Assessment
Linux Security Hardening Platform
Security Score
Prevent direct root login via SSH to reduce attack surface
sudo sed -i "s/#PermitRootLogin yes/PermitRootLogin no/" /etc/ssh/sshd_config && sudo systemctl restart sshd
Move SSH from default port 22 to reduce automated attacks
sudo sed -i "s/#Port 22/Port 2222/" /etc/ssh/sshd_config && sudo systemctl restart sshd
Use key-based authentication instead of passwords
sudo sed -i "s/#PubkeyAuthentication yes/PubkeyAuthentication yes/" /etc/ssh/sshd_config && sudo systemctl restart sshd
Force key-based authentication only
sudo sed -i "s/#PasswordAuthentication yes/PasswordAuthentication no/" /etc/ssh/sshd_config && sudo systemctl restart sshd
Activate Ubuntu's Uncomplicated Firewall
sudo ufw --force enable
Block all incoming connections by default
sudo ufw default deny incoming && sudo ufw default allow outgoing
Allow SSH connections on custom port
sudo ufw allow 2222/tcp
Enable firewall logging for monitoring
sudo ufw logging on
Prevent core dumps that could leak sensitive information
echo "* hard core 0" | sudo tee -a /etc/security/limits.conf && echo "fs.suid_dumpable=0" | sudo tee -a /etc/sysctl.conf
Enable Address Space Layout Randomization
echo "kernel.randomize_va_space=2" | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Prevent non-root users from reading kernel logs
echo "kernel.dmesg_restrict=1" | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Install and configure Fail2Ban for intrusion prevention
sudo apt install fail2ban -y && sudo systemctl enable fail2ban && sudo systemctl start fail2ban
Protect SSH service with Fail2Ban
echo -e "[sshd]\nenabled = true\nport = ssh\nfilter = sshd\nlogpath = /var/log/auth.log\nmaxretry = 3\nbantime = 3600" | sudo tee /etc/fail2ban/jail.local
Install Advanced Intrusion Detection Environment
sudo apt install aide -y && sudo aideinit && sudo mv /var/lib/aide/aide.db.new /var/lib/aide/aide.db
Prevent system from acting as a router
echo "net.ipv4.ip_forward=0" | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Protect against SYN flood attacks
echo "net.ipv4.tcp_syncookies=1" | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Prevent ICMP redirect attacks
echo "net.ipv4.conf.all.accept_redirects=0" | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Configure strong password requirements
sudo apt install libpam-pwquality -y && echo "minlen=12" | sudo tee -a /etc/security/pwquality.conf
Lock accounts after failed login attempts
echo "auth required pam_tally2.so deny=5 unlock_time=900" | sudo tee -a /etc/pam.d/common-auth