Introduction
Securing your Linux VPS is crucial for protecting sensitive data and ensuring system integrity. This tutorial provides essential security measures you can implement to safeguard your server from unauthorized access and attacks.
Security Measures
Step 1: Update Your System Regularly
- Keep your server’s packages up to date to ensure you have the latest security patches and fixes:
sudo apt update && sudo apt upgrade
Step 2: Secure SSH Access
- Change the default SSH port from 22 to a custom port to reduce brute force attacks:
Find the line that sayssudo nano /etc/ssh/sshd_config
Port 22
and change it to your chosen port number. - Disallow root login over SSH to limit admin access:
PermitRootLogin no
- Use SSH key authentication instead of passwords for more secure access.
ssh-keygen -t rsa -b 4096
- Restart the SSH service to apply changes:
sudo systemctl restart sshd
Step 3: Configure a Firewall with UFW
- Enable UFW and allow only essential services:
sudo ufw allow OpenSSH
Define additional rules for other necessary services.sudo ufw enable
- Check the status of UFW to confirm active rules:
sudo ufw status
Step 4: Install Fail2Ban
- Install Fail2Ban to protect against brute force attacks:
sudo apt install fail2ban
- Enable and start the Fail2Ban service:
sudo systemctl enable fail2ban
sudo systemctl start fail2ban
Step 5: Monitor Server Activity
- Regularly check system logs for suspicious activity:
sudo tail -f /var/log/auth.log
- Use tools like Logwatch to automate and simplify log monitoring.
Conclusion
By following these steps, you've strengthened the security of your Linux VPS. Regularly update your security practices to adapt to emerging threats and ensure your system remains secure