Advertisement
linuxserver โ€ข Learn how to harden your Linux server with practical security steps like SSH security, firewalls, updates, user permissions, intrusion protection, and backups. A beginner-friendly and realistic guide.

Linux Server Hardening Guide: Simple Security Steps Every Admin Should Do

5 Min Read Verified Content

If you run a Linux server on the internet, you quickly learn one simple truth:

๐Ÿ‘‰ Someone, somewhere, is always trying to break into it.

Even if your server is tiny. Even if itโ€™s just a test site. Bots donโ€™t care โ€” they scan everything.

Thatโ€™s why Linux hardening matters.
Not because we want to be paranoid โ€” but because security is about reducing risk, layer by layer.

In this guide, Iโ€™ll walk through the core security steps I personally apply on new servers. Nothing extreme. Nothing complicated. Just practical protection you can actually maintain.


๐Ÿ” Step 1 โ€” Secure SSH Access (Your Serverโ€™s Front Door)

SSH is the main target for brute-force attacks.

Hereโ€™s what I always do:

โœ” Disable root login

Edit:

sudo nano /etc/ssh/sshd_config

Set:

PermitRootLogin no

Root access should require sudo โ€” not direct login.

โœ” Use SSH keys instead of passwords

Generate a key on your local machine:

ssh-keygen

Copy it:

ssh-copy-id user@server

Then disable password login:

PasswordAuthentication no

Restart SSH after changes:

sudo systemctl restart ssh

โœ” (Optional) Change SSH port

Not security-proof โ€” but reduces bot noise:

Port 2222

๐Ÿ›ก Step 2 โ€” Enable a Firewall

If you havenโ€™t already, UFW is simple and effective.

Allow SSH first:

sudo ufw allow 2222/tcp

(or 22 if default)

Allow web:

sudo ufw allow 80 sudo ufw allow 443

Then enable:

sudo ufw enable

Done ๐Ÿ‘


๐Ÿ”„ Step 3 โ€” Keep Your System Updated

Outdated software = open doors.

Update regularly:

sudo apt update && sudo apt upgrade

or on RHEL/CentOS:

sudo yum update

I like to automate security patches โ€” but never blindly auto-upgrade everything on production without testing, especially databases.

Balance is key.


๐Ÿ‘ฅ Step 4 โ€” Limit Who Can Do What (User Permissions)

Good rule:

๐Ÿ‘‰ No one should have more access than they need.

Create normal users โ€” donโ€™t use root daily.

Add a user:

sudo adduser john

Give sudo only when needed:

sudo usermod -aG sudo john

Check who has sudo:

getent group sudo

If someone leaves your team โ€” remove access. Immediately.


๐Ÿงฑ Step 5 โ€” Install Fail2Ban (Stops Brute-Force Attacks)

Fail2Ban monitors logs and bans abusive IPs.

Install:

sudo apt install fail2ban

Enable:

sudo systemctl enable fail2ban sudo systemctl start fail2ban

Check:

sudo fail2ban-client status

It quietly protects you in the background.


๐Ÿ” Step 6 โ€” Monitor Logs (Your Server Talks โ€” Listen)

Useful logs:

/var/log/auth.log /var/log/syslog /var/log/nginx/error.log journalctl -xe

Sometimes the first sign of an attack is right there.

I recommend checking occasionally โ€” especially after unusual behavior.


๐Ÿ“ฆ Step 7 โ€” Remove Stuff You Donโ€™t Need

Every service = another thing to attack.

List services:

systemctl list-units --type=service

Ask yourself:

๐Ÿ‘‰ โ€œDo I really need this running?โ€

If not, disable it:

sudo systemctl disable service-name sudo systemctl stop service-name

Minimalism = security.


๐Ÿ”’ Step 8 โ€” Secure File Permissions

Web directories should NOT be world-writable.

Example:

sudo chown -R www-data:www-data /var/www/html sudo chmod -R 755 /var/www/html

Avoid 777 unless you love chaos ๐Ÿ˜„


๐Ÿงช Step 9 โ€” Protect Against Port Scans & Ping Floods (Optional)

Block ping (optional โ€” not always recommended):

sudo nano /etc/sysctl.conf

Add:

net.ipv4.icmp_echo_ignore_all = 1

Apply:

sudo sysctl -p

This reduces visibility โ€” but may break monitoring. Use carefully.


๐Ÿ—‚ Step 10 โ€” Always Have Backups

Hard truth:

Security is never absolute. Backups are survival.

Back up:

โœ” databases
โœ” configs
โœ” app files
โœ” SSL certs

Test restore occasionally.

A backup youโ€™ve never testedโ€ฆ
is just a hope, not a plan.


๐Ÿšจ Step 11 โ€” Disable Root Cron Abuse

Only allow necessary cron jobs.

List:

crontab -l sudo ls /etc/cron.*

Delete unknown jobs immediately โ€” malware often hides here.


๐Ÿง  Security Mindset (This Matters More Than Tools)

Linux hardening isnโ€™t about installing fancy tools.

Itโ€™s about habits:

โœ” minimal access
โœ” updates
โœ” monitoring
โœ” backups
โœ” least privilege
โœ” logs

And most importantlyโ€ฆ

๐Ÿ‘‰ thinking before doing anything as root.


๐Ÿงฉ Extra Security Ideas (When Youโ€™re Ready)

Later, you can also explore:

๐Ÿ” 2FA SSH
๐Ÿ” SELinux / AppArmor
๐Ÿ” WAF for websites (like Cloudflare)
๐Ÿ” IDS tools (OSSEC, Wazuh)
๐Ÿ” Audit logs

But donโ€™t overwhelm yourself โ€” start simple.


๐ŸŽฏ Final Thoughts

Hardening a Linux server is not a one-time job.

Itโ€™s a mindset.

With just the steps above, you already reduce risk massively:

โœ… SSH secured
โœ… Firewall enabled
โœ… Brute-force blocked
โœ… Permissions controlled
โœ… Logs monitored
โœ… Backups ready

And all without breaking your workflow.

Because security should protect you โ€”
not make your life miserable.

Advertisement
Back to Linuxserver