Console Login

Lock Down Your Linux Box: Essential Server Hardening for 2011

Lock Down Your Linux Box: Essential Server Hardening for the Paranoid

I recently watched a client's unmanaged dedicated server in Oslo get turned into a botnet zombie in less than 14 minutes. They deployed a fresh CentOS 5.6 install, left the root password as the default provided by the host, and went to grab a coffee. By the time they came back, the bandwidth graph was flatlining at 100Mbps outbound. The culprit? A simple brute-force script likely running out of a compromised box in Eastern Europe.

In the world of VPS Norway hosting, relying on "security through obscurity" is a death sentence. Whether you are running a high-traffic e-commerce site adhering to the strict Norwegian Personal Data Act (Personopplysningsloven) or just a dev server, you need to harden your system before you even install Apache.

This isn't a theoretical guide. This is the checklist I use for every production server I deploy. If you are running on CoolVDS, you start with a clean slate, but it is your responsibility to keep it that way.

1. Secure SSH: The First Line of Defense

Port 22 is the first door hackers knock on. If you leave root login enabled with a password, you are practically inviting them in. We need to disable root login and switch to Key-Based Authentication.

First, generate your keys locally (if you haven't already):

ssh-keygen -t rsa -b 4096

Once you have pushed your public key to the server (~/.ssh/authorized_keys), edit the SSH daemon configuration. This is where 90% of automated attacks fail.

Open the config file:

vi /etc/ssh/sshd_config

Find and change these directives. Do not simply uncomment them; ensure they are set exactly as follows:

# Disable root login. Create a sudo user instead.
PermitRootLogin no

# Disable password authentication. Keys only.
PasswordAuthentication no

# Restrict access to specific users (optional but recommended)
AllowUsers yourusername

# Change the default port (Security through obscurity, but cuts log noise)
Port 2222

Save and restart the service. On RHEL/CentOS 6:

service sshd restart
Pro Tip: Before you close your current terminal session, open a new terminal window and try to connect. If you messed up the config and close your current session, you are locked out. I've seen senior admins drive to data centers at 3 AM because of this. Don't be that guy.

2. The Firewall: Learning to Love iptables

Forget fancy GUIs. In 2011, iptables is the only firewall you should trust on a Linux server. It processes packets at the kernel level, ensuring virtually zero latency impact, which is crucial for low latency applications.

We want a "Default Drop" policy. This means if traffic isn't explicitly allowed, it gets killed.

Here is a standard baseline configuration script. Save this as firewall_setup.sh:

#!/bin/bash

# 1. Flush existing rules
iptables -F

# 2. Set default policies to DROP
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT

# 3. Allow loopback traffic (critical for local services like MySQL)
iptables -A INPUT -i lo -j ACCEPT

# 4. Allow established connections (so you don't lock yourself out)
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# 5. Allow SSH (Make sure this matches your new port defined above!)
iptables -A INPUT -p tcp --dport 2222 -j ACCEPT

# 6. Allow Web Traffic
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT

# Save settings
/sbin/service iptables save

echo "Firewall locked down."

Run this, and verify with iptables -L -v. You should see packets being dropped in the counters if you are under attack.

3. Ban the Bots with Fail2Ban

Even with keys and a custom port, bots will hammer your SSH port. Fail2Ban monitors your log files (like /var/log/secure) and updates your iptables rules dynamically to ban IP addresses that show malicious signs.

Install it (requires EPEL repo on CentOS):

yum install fail2ban

Configure the jail in /etc/fail2ban/jail.local:

[ssh-iptables]
enabled  = true
filter   = sshd
action   = iptables[name=SSH, port=2222, protocol=tcp]
logpath  = /var/log/secure
maxretry = 3
bantime  = 3600

This configuration bans an IP for an hour after 3 failed attempts. It’s simple, effective, and keeps your logs clean.

4. The Hardware Factor: Isolation Matters

Software hardening is useless if your neighbor on the physical host can exploit a kernel vulnerability to break into your container. This is the dirty secret of cheap managed hosting providers using older OpenVZ setups with shared kernels.

At CoolVDS, we prioritize strict isolation. We use hypervisors that provide true hardware virtualization (HVM). This means your OS kernel is yours alone. If a neighbor crashes their kernel, you stay up. If they get compromised, the attacker hits a hypervisor wall, not your file system. This architecture is essential for compliance with EU data directives.

Furthermore, while many hosts are still spinning 7.2k SATA drives, we are aggressive about I/O performance using enterprise SAS and emerging high-speed SSD configurations. Fast storage doesn't just mean faster website loads; it means your database can write audit logs without locking up during a DDoS attack.

5. Keep It Updated

It sounds obvious, but the number of servers running kernel versions from 2009 is terrifying. Vulnerabilities are discovered weekly. Automate your security updates or make it a Monday morning ritual.

yum update -y

Check your kernel version frequently with uname -r. If you are running mission-critical apps, subscribe to the CentOS-announce or Debian-security-announce mailing lists. Do not wait for a blog post to tell you about a zero-day exploit.

Final Thoughts

Security is not a product; it's a process. By disabling root login, configuring a strict firewall, and utilizing tools like Fail2Ban, you eliminate 99% of automated threats targeting your server.

For the remaining 1%, you need robust infrastructure that offers ddos protection capabilities and reliable hardware. Don't build your fortress on a swamp. Start with a solid foundation.

Ready to deploy a secure environment? Spin up a hardened instance on CoolVDS today and experience the difference true isolation makes.