Join our Telegram: @serverrental_wiki | BTC Analysis | Trading Signals | Telegraph
Server Security Checklist
Jump to navigation
Jump to search
Server Security Checklist
A comprehensive security audit is crucial for any production server to protect sensitive data, maintain service availability, and prevent unauthorized access. This checklist provides a practical, hands-on approach to auditing and hardening your Linux server.
Prerequisites
Before beginning, ensure you have:
- Root or sudo access to the server.
- Basic understanding of Linux command line and networking concepts.
- SSH access to the server.
- A reliable backup of your server's data and configuration.
- A list of all running services and their purpose.
1. Secure SSH Access
SSH (Secure Shell) is the primary way to manage your server remotely. Securing it is paramount.
- Disable Root Login:
- * Edit the SSH configuration file:
sudo nano /etc/ssh/sshd_config
- * Find the line
PermitRootLoginand change it to: PermitRootLogin no
- * Why: Direct root login bypasses user privilege escalation and is a common target for brute-force attacks.
- * Troubleshooting: If you accidentally lock yourself out, you may need console access or to reboot into single-user mode to revert the change.
- # Use SSH Keys Instead of Passwords:
- # * Generate an SSH key pair on your local machine:
- #
ssh-keygen -t rsa -b 4096
- # * Copy your public key to the server:
- #
ssh-copy-id your_username@your_server_ip
- # * Why: SSH keys are significantly more secure than passwords and are immune to brute-force attacks.
- # * Troubleshooting: Ensure file permissions on
~/.ssh/authorized_keyson the server are correct (usually 600). - #
- # # Change the Default SSH Port:
- # # * In
/etc/ssh/sshd_config, changePort 22to a non-standard port (e.g.,Port 2222). - # # * Why: While not a foolproof security measure, it significantly reduces automated scanning and brute-force attempts targeting the default port.
- # # * Troubleshooting: Remember to specify the new port when connecting:
ssh -p 2222 your_username@your_server_ip. - # #
- # # # Limit SSH User Access:
- # # # * In
/etc/ssh/sshd_config, useAllowUsersorDenyUsersdirectives. - # # #
AllowUsers user1 user2
- # # # * Why: Restricts who can log in via SSH, minimizing the attack surface.
- # # #
- # # # # Restart SSH Service:
- # # # #
sudo systemctl restart sshd
- # # # # * Why: Applies the configuration changes.
- #
- # == 2. Firewall Configuration ==
- #
- # A firewall is your server's first line of defense against unwanted network traffic.
- #
- # # Install and Configure UFW (Uncomplicated Firewall):
- # # * Install UFW if not already present:
- # #
sudo apt update && sudo apt install ufw
- # # * Why: UFW simplifies firewall management.
- # #
- # # # Set Default Policies:
- # # #
sudo ufw default deny incoming
- # # #
sudo ufw default allow outgoing
- # # # * Why: Denies all incoming connections by default, allowing only explicitly permitted services.
- # # #
- # # # # Allow Necessary Services:
- # # # # * Allow SSH (using your custom port if changed):
- # # # #
sudo ufw allow 2222/tcp
- # # # # * Allow HTTP/HTTPS:
- # # # #
sudo ufw allow 80/tcp
- # # # #
sudo ufw allow 443/tcp
- # # # * Why: Opens specific ports for essential services.
- # # # * Troubleshooting: If you lose SSH access, you'll need console access to re-enable port 2222.
- # # #
- # # # # Enable the Firewall:
- # # # #
sudo ufw enable
- # # # # * Why: Activates the firewall rules.
- # # # #
- # # # # # Check Firewall Status:
- # # # # #
sudo ufw status verbose
- # # # # # * Why: Verifies that the rules are active and correctly configured.
- # # # #
- # # # # == 3. Regular System Updates ==
- # # #
- # # # Unpatched vulnerabilities are a major security risk.
- # # #
- # # # # Update Package Lists and Upgrade Packages:
- # # # #
sudo apt update && sudo apt upgrade -y
- # # # # * Why: Ensures all installed software is up-to-date with the latest security patches. The
-yflag automatically answers yes to prompts. - # # # * Troubleshooting: Sometimes upgrades require a reboot. Monitor for prompts or messages indicating this.
- # # #
- # # # # Enable Automatic Security Updates (Optional but Recommended):
- # # # # * Install the unattended-upgrades package:
- # # # #
sudo apt install unattended-upgrades
- # # # # * Configure it (e.g.,
/etc/apt/apt.conf.d/50unattended-upgrades). - # # # # * Why: Automates the patching process for critical security updates.
- # # # * Security Implication: While convenient, ensure you have rollback plans in case an automatic update causes issues.
- # # #
- # # # == 4. Minimize Installed Software ==
- # #
- # # Every installed package is a potential entry point for attackers.
- # #
- # # # List Installed Packages:
- # # #
dpkg -l | less
(Debian/Ubuntu) - # # #
rpm -qa | less
(CentOS/RHEL) - # # # * Why: Helps you identify unnecessary software.
- # # #
- # # # # Remove Unused Packages:
- # # # #
sudo apt autoremove --purge
(Debian/Ubuntu) - # # # #
sudo yum autoremove
(CentOS/RHEL) - # # # * Why: Removes packages that were installed as dependencies but are no longer needed.
- # # #
- # # # # Uninstall Unnecessary Services:
- # # # # * Identify running services:
- # # # #
sudo systemctl list-units --type=service --state=running
- # # # # * Stop and disable a service if not needed:
- # # # #
sudo systemctl stop apache2 && sudo systemctl disable apache2
- # # # * Why: Reduces the attack surface by disabling or removing services you don't actively use.
- # #
- # # == 5. Intrusion Detection & Monitoring ==
- #
- # Proactive monitoring can help detect and respond to security incidents quickly.
- #
- # # Install and Configure Fail2ban:
- # # * Install Fail2ban:
- # #
sudo apt install fail2ban
- # # * Configure it by copying the default jail.conf to jail.local:
- # #
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
- # # * Edit
jail.localto customize settings, e.g., SSH port, ban time, and email notifications. - # # * Why: Scans log files for malicious activity (like repeated failed login attempts) and temporarily or permanently bans the offending IP addresses.
- # # * Troubleshooting: Ensure Fail2ban is enabled and running:
sudo systemctl status fail2ban. Check its logs:/var/log/fail2ban.log. - # #
- # # # Monitor System Logs:
- # # # * Regularly review logs in
/var/log/, especially: - # # # *
/var/log/auth.log(orsecureon RHEL-based systems) for authentication attempts. - # # # *
/var/log/syslog(ormessages) for general system activity. - # # # * Application-specific logs (e.g., web server logs).
- # # * Why: Log analysis is crucial for identifying suspicious patterns and security breaches.
- # # * Tools: Consider tools like
logwatchor centralized logging solutions (e.g., ELK stack, Graylog) for larger deployments. - # #
- # # # Implement File Integrity Monitoring (Optional):
- # # # * Install AIDE (Advanced Intrusion Detection Environment):
- # # #
sudo apt install aide aide-common
- # # # * Initialize the database:
- # # #
sudo aideinit
- # # # * Run a check:
- # # #
sudo aide.wrapper --check
- # # * Why: Detects unauthorized modifications to critical system files.
- # # * Security Implication: The AIDE database itself must be protected. Store a copy offline if possible.
- #
- # == 6. User and Permission Management ==
- #
- # Least privilege principle is key.
- #
- # # Review User Accounts:
- # #
cat /etc/passwd
- # # * Why: Identify any dormant or unauthorized user accounts.
- # #
- # # # Remove Unused User Accounts:
- # # #
sudo userdel -r username
- # # * Why: Removes accounts that are no longer needed, reducing potential entry points.
- # #
- # # # Use Strong Passwords and Enforce Policies:
- # # # * Ensure users have strong, unique passwords. Consider password complexity requirements and expiration policies using PAM (Pluggable Authentication Modules).
- # # * Why: Weak passwords are easily compromised.
- # #
- # # # Regularly Review File Permissions:
- # # # * Use
findto locate world-writable files or directories: - # # #
sudo find / -xdev -type d -perm -0002 -print
- # # #
sudo find / -xdev -type f -perm -0002 -print
- # # * Why: Prevents unauthorized modification of sensitive files.
- #
- # == 7. Security Hardening for Web Servers (Example: Nginx) ==
- #
- # If your server hosts web applications, hardening the web server is critical.
- #
- # # Keep Web Server Software Updated:
- # # * Follow the instructions in Section 3.
- # #
- # # # Configure SSL/TLS:
- # # # * Obtain and install an SSL certificate (e.g., Let's Encrypt).
- # # * Why: Encrypts traffic between the client and server, protecting data in transit.
- # # * See also: Let's Encrypt
- # #
- # # # Disable Unnecessary Modules:
- # # # * Consult your web server's documentation to disable modules that are not in use.
- # # * Why: Reduces the attack surface.
- # #
- # # # Implement Security Headers:
- # # # * Configure headers like
Strict-Transport-Security,X-Frame-Options,X-Content-Type-Options, andContent-Security-Policyin your web server configuration. - # # * Why: Mitigates various web vulnerabilities like clickjacking, XSS, and man-in-the-middle attacks.
- # #
- # # # Limit Request Methods and Body Sizes:
- # # # * Configure your web server to only allow necessary HTTP methods (e.g., GET, POST) and limit the size of request bodies to prevent certain types of denial-of-service attacks.
- # #
- # # == 8. Regular Audits and Testing ==
- #
- # Security is an ongoing process.
- #
- # # Perform Regular Vulnerability Scans:
- # # * Use tools like OpenVAS, Nessus, or Nmap scripts to scan your server for known vulnerabilities.
- # # * Why: Identifies potential weaknesses before attackers do.
- # #
- # # # Review Security Logs Periodically:
- # # * Dedicate time to manually review critical security logs.
- # # * Why: Helps catch subtle or ongoing threats that automated tools might miss.
- # #
- # # # Test Your Backups:
- # # * Regularly attempt to restore data from your backups to ensure they are valid and complete.
- # # * Why: A backup is useless if it cannot be restored.
- #
- # == Dedicated Servers for Enhanced Security ==
- #
- # For critical applications requiring maximum control and security, consider dedicated servers. Dedicated servers, such as those offered at PowerVPS, provide full root access, allowing you to implement these security measures with complete freedom and without the overhead of shared environments. This level of control is essential for implementing advanced security configurations and ensuring compliance with stringent security policies.
- #
- # == Conclusion ==
- #
- # Implementing this checklist is a significant step towards a more secure server environment. Remember that security is not a one-time task but an ongoing commitment. Regularly review and update your security practices as threats evolve.
- #
- #
- #
- #