Course contentsShow
← Security
Lesson 1435 of 3,05229. Operating System Security - HardeningFree lesson

Service User Accounts and Privileges

Apply least privilege by running services under dedicated non-root users with minimal permissions and capabilities.

Service User Accounts and Privileges

What you'll learn: How to run services under dedicated, unprivileged user accounts to limit damage if they're compromised.

The Core Principle

Services like web servers, databases, and application daemons should never run as root or Administrator. Instead, create dedicated user accounts for each service with only the minimum permissions needed to function. Think of it like giving a delivery driver the key to just the loading dock—not a master key to your entire building.

When a service runs as root, an attacker who compromises it gains full system control. By using a dedicated, limited account, you contain the blast radius of any breach.

How It Works

Each service gets its own user account that:

  • Cannot log in interactively (no shell access)
  • Has no home directory or minimal restricted one
  • Owns only the files/directories the service needs
  • Cannot read sensitive system files
  • Has no sudo privileges

On Linux, you might create a user for a web service:

useradd --system --no-create-home --shell /sbin/nologin webservice

Then configure the service (via systemd, as you learned in step 1433) to run as this user:

[Service]
User=webservice
Group=webservice

The files the service needs should be owned by this user, but nothing else:

chown webservice:webservice /var/www/app
chmod 750 /var/www/app

Why This Matters

If your web service is exploited, the attacker inherits only webservice user permissions—they can't read /etc/shadow, modify system configurations, or access other services' data.

Key Takeaway: Always run services under dedicated, non-privileged user accounts with minimal permissions—never as root—to enforce least privilege and contain potential breaches.