Server Security: 5 Ways to Stop Breaches
Compare 5 server security methods to stop breaches. Fix weak SSH, patch systems, and secure your infrastructure with practical steps.

On this page
TL;DR — Key takeaways
- Disable root SSH login and use key-based authentication to eliminate 90% of brute-force attacks.
- Automate patching for the OS and web server, but always test in a staging environment first.
- Use a host-based firewall like UFW or nftables to restrict inbound traffic to only necessary ports.
- Implement fail2ban to automatically block IP addresses after repeated failed login attempts.
- Regularly audit user accounts and remove unused credentials to reduce the internal attack surface.
Server security isn't about installing one magic tool. It's about layering simple, effective controls that work together. In support tickets I handle, the usual culprit is a misconfigured SSH service or an unpatched web server.
This guide compares five core server security methods. You'll see what each does, where it fails, and how to combine them for a solid defense. No fluff, just the steps that actually hold up under pressure.
SSH Hardening: The First Line of Defense
SSH is the most common entry point for attackers. If you leave password authentication enabled, bots will try thousands of combinations per minute. The fix is straightforward but requires care.
First, generate a key pair on your local machine. Copy the public key to your server. Then edit /etc/ssh/sshd_config. Set 'PasswordAuthentication no' and 'PermitRootLogin no'. Restart the SSH service. Always keep your current session open until you confirm the new key works in a new terminal. Locking yourself out is a common mistake.
Changing the port from 22 to something like 2222 helps filter out low-level scanners. It's not a security boundary on its own, but it reduces log noise. Combine it with key-based auth for real protection.
- Generate an Ed25519 key pair for better security than RSA.
- Use 'ssh-copy-id' to transfer keys securely.
- Test the new connection before closing the old one.
- Set 'MaxAuthTries 3' to limit login attempts per connection.
Firewall Configuration: Controlling Access
A firewall defines what traffic reaches your services. Without it, every port is open to the world. UFW (Uncomplicated Firewall) is the easiest to manage on Ubuntu and Debian systems.
Start by allowing SSH on your new port. Then allow HTTP and HTTPS if you run a web server. Deny everything else by default. The command 'ufw default deny incoming' sets this baseline. Enable the firewall with 'ufw enable'.
For more complex setups, nftables offers finer control. But for most hosting customers, UFW is sufficient. Check your rules with 'ufw status verbose' to ensure only intended ports are open.
- Allow SSH before enabling the firewall to avoid lockout.
- Use 'ufw allow 2222/tcp' for your custom SSH port.
- Deny all incoming traffic by default.
- Review rules after every change with 'ufw status'.
Patch Management: Closing Known Holes
Unpatched software is an open door. Attackers scan for known vulnerabilities daily. If you run an outdated version of Apache, Nginx, or PHP, you're at risk.
Enable unattended-upgrades on Ubuntu. This automatically installs security patches. On CentOS or RHEL, use 'yum update' or 'dnf update' regularly. Always test updates in a staging environment first. A broken web server is worse than a patched one.
Keep an eye on your package manager's output. If a package fails to update, investigate why. Sometimes a dependency conflict blocks the fix. Resolve it manually if needed.
- Enable unattended-upgrades for automatic security patches.
- Test updates in a staging environment before production.
- Check for failed packages after each update cycle.
- Document which versions you're running for quick reference.
Intrusion Detection: fail2ban and Monitoring
Even with strong SSH and firewall rules, attackers will probe. fail2ban watches your logs and bans IPs after repeated failures. It's a simple but effective layer.
Install fail2ban and enable the sshd jail. Set 'bantime' to 1 hour and 'maxretry' to 3. This means an IP gets banned for an hour after 3 failed attempts. Check the logs in /var/log/fail2ban.log to see what's being blocked.
For web servers, enable the nginx or apache jail. This protects against brute-force attacks on login forms. Combine fail2ban with your firewall for a dynamic blocklist.
- Enable the sshd jail in fail2ban.conf.
- Set maxretry to 3 for quick bans.
- Check /var/log/fail2ban.log for blocked IPs.
- Enable web server jails for login form protection.
User Account Management: Reducing Internal Risk
Unused accounts are a liability. If an employee leaves and their account stays active, it's a potential entry point. Audit your user list regularly.
Remove any accounts you don't recognize. Use 'sudo getent passwd' to list all users. Check for accounts with UID 0 (root-equivalent) that shouldn't exist. Lock unused accounts with 'sudo usermod -L username'.
For daily administration, use a non-root user with sudo privileges. This limits damage if a command goes wrong. Never run scripts as root unless absolutely necessary.
- List all users with 'sudo getent passwd'.
- Remove or lock unused accounts.
- Use a non-root user with sudo for daily tasks.
- Audit sudoers file for unnecessary privileges.
Quick troubleshooting checklist
- Backup your server configuration and data before making changes.
- Disable password authentication for SSH in /etc/ssh/sshd_config.
- Change the default SSH port from 22 to a non-standard port.
- Install and configure a host-based firewall to allow only required ports.
- Set up automatic security updates for the operating system.
- Install fail2ban to monitor logs and ban malicious IPs.
- Create a non-root user with sudo privileges for daily administration.
- Verify that all changes work correctly before closing your current SSH session.
FAQ
What is the most effective first step for server security?
Disable password authentication for SSH and switch to key-based authentication. This single change blocks the vast majority of automated brute-force attacks that target default credentials.
How often should I patch my server?
Apply security patches immediately upon release for critical vulnerabilities. For general updates, a weekly or monthly schedule is sufficient, provided you test changes in a staging environment first.
Is changing the SSH port enough to secure my server?
No. Changing the port reduces noise from automated scanners but does not stop targeted attacks. It must be combined with key-based authentication, fail2ban, and a firewall to be effective.
Related articles
- Hosting OperationsServer Security Hardening 2026: 6 Steps [Solved]Compare six server hardening approaches and choose the right one. SSH lockdown, firewall rules, patch cadence, and intrusion detection for Linux and Windows.
- Hosting OperationsServer Security Hardening Checklist 2026: Essential Steps: Comparison and Best PracticesCompare server hardening approaches for Linux and Windows. Practical checklist with firewall, SSH, patch management, and monitoring trade-offs for different
- Hosting OperationsServer Security Best Practices 2026: Protect Your Infrastructure: Comparison and Best PracticesCompare server security approaches for 2026. Practical hardening steps, SSH configuration, firewall strategies, and zero-trust implementation guidance.
- Hosting OperationsServer Security Hardening 2026: 9 Steps ComparedCompare nine server hardening approaches to close exploit vectors. Pick the right method for your infrastructure with clear trade-offs.
- Hosting OperationsVPS Hosting 2026: 7 Security Hardening Steps [Solved]Secure your VPS hosting against common threats with these seven hardening steps. Covers SSH lockdown, firewall rules, and audit verification.
- Hosting OperationsHow to Secure Your Server in 2024: Practical GuideStep-by-step server hardening guide: SSH configuration, firewall setup, automated updates, and monitoring to protect your infrastructure.