How to Disable Unnecessary Services to Reduce Attack Surface

Every running service is a potential attack vector — disabling anything not genuinely needed reduces your server's overall attack surface with essentially no downside for services you're not actually using.

Why This Matters

A vulnerability in a service you don't even use is still a vulnerability on your server — the fewer active services, the fewer potential entry points for an attacker, and the less you need to monitor and patch.

Step 1 — List All Currently Running Services

systemctl list-units --type=service --state=running

Step 2 — Review Each One Critically

For each running service, ask: do I actually need this? Is it something I intentionally installed and use, or a default that came with the base image/template and isn't actually necessary for my use case?

Common Services Worth Reviewing on a Minimal VPS

ServiceConsider Disabling If
Printing services (cups)You have no printing needs (virtually always true for a VPS)
Bluetooth servicesNo relevant hardware/use case on a VPS (virtually always true)
Avahi/mDNSNot using local network service discovery
NFS/rpcbindNot using NFS-based file sharing

The specific set of unnecessary default services varies by base image/distribution — review your actual running services list rather than assuming any generic checklist perfectly matches your specific system.

Step 3 — Stop and Disable Unneeded Services

sudo systemctl stop SERVICE_NAME
sudo systemctl disable SERVICE_NAME

stop halts it immediately; disable prevents it from starting again on future boots — do both for a genuinely permanent removal from your running services.

Step 4 — Consider Uninstalling, Not Just Disabling

sudo apt purge PACKAGE_NAME

For services you're confident you'll never need, fully removing the package (not just disabling the service) further reduces attack surface and eliminates any need to track/patch that software at all.

Step 5 — Verify Nothing Broke

After disabling a service, verify your actual applications/workflows still function correctly — some services have non-obvious dependencies; test thoroughly before considering the cleanup complete.

Checking Listening Ports as a Cross-Check

sudo ss -tulnp

Cross-reference actively listening ports against your list of intentionally-running services — anything listening that you don't recognize deserves investigation.

Being Cautious with Core System Services

Don't disable services fundamental to system operation (systemd-journald, systemd-logind, and similar core components) without understanding their specific purpose — focus this exercise on genuinely optional, unused services, not core system infrastructure.

Documenting What You Disabled and Why

Keep a record of what you disabled/removed and the reasoning — useful if you later need to troubleshoot something unexpected, or if a future you (or teammate) wonders why a particular service isn't running.

Common Errors

Disabled a service that turned out to be needed by something else — re-enable it (sudo systemctl enable --now SERVICE_NAME) and investigate the actual dependency before attempting removal again, if still desired.

Continue Reading

Browse more articles in Server Security & Hardening.

  • reduce attack surface, disable unnecessary services, minimize running services linux, server hardening services
  • 0 Користувачі, які знайшли це корисним
Ця відповідь Вам допомогла?

Схожі статті

SSH Hardening: Change the Port, Disable Root Login & Use SSH Keys (Ubuntu & Debian)

SSH is the front door to your VPS — and by default it listens on a well-known port, often...

How to Install and Configure Fail2Ban on Ubuntu & Debian (Complete Guide)

Fail2Ban monitors your server's log files and automatically blocks (bans) IP addresses that show...

How to Configure UFW Firewall on a Linux VPS (Ubuntu & Debian)

UFW (Uncomplicated Firewall) is the standard firewall front-end on Ubuntu and Debian. A correctly...

How to Enable Two-Factor Authentication (2FA) for SSH on a Linux VPS

Two-Factor Authentication (2FA) adds a second layer of protection to SSH: even if your password...

VPS Security Checklist for Beginners: 12 Essential Steps

Every new VPS is deployed with default settings that are convenient but not secure. This...