LINUX-PRODUCTION Contents

Users, Groups, and Service Accounts

Create least-privilege users, group policies, and predictable ownership for services.

On this page

Why User Strategy Matters in Production

On a production server, the question is not “can it run?” but “who can run it?” User and group design determines blast radius during incidents, privilege escalation risk, and auditability. Running everything as root is not convenience — it is future outage material.

The Golden Rule: Root Is for Maintenance Only

Root should never run your application. Root should:

  • Install packages
  • Manage system configuration
  • Perform controlled maintenance

Your services must run as dedicated system users.

Service Account Pattern

Every production service should have its own system user.

sudo useradd --system --no-create-home --shell /usr/sbin/nologin myapp

This creates:

  • No login capability
  • No home directory
  • Isolated ownership boundary

Ownership Strategy

Application directories should be owned by the service user:

chown -R myapp:myapp /srv/myapp

Never make application directories writable by everyone (chmod 777 is not a solution).

Group-Based Access Model

Instead of granting individual permissions repeatedly, use groups. Example:

groupadd deploy
usermod -aG deploy alice
usermod -aG deploy bob

Now grant directory access once:

chgrp -R deploy /srv/myapp
chmod -R 750 /srv/myapp

Understanding umask

umask defines default permissions for new files. On production systems, a safe default is:

umask 027

This ensures:

  • No world-readable secrets
  • Group collaboration remains possible

Sudo Minimalism

Instead of giving full root access, restrict commands:

alice ALL=(ALL) NOPASSWD: /bin/systemctl restart myapp

This limits blast radius dramatically.

Directory Permission Model

Production-safe pattern:

  • 750 for application directories
  • 640 for config files
  • 600 for secrets

Common Production Mistakes

  • Running Node, PHP, Python apps as root
  • Using chmod 777 during “quick fixes”
  • Sharing one system user across multiple services
  • Putting secrets in user home directories

Auditing Your Server

ps aux --sort=user
ls -l /srv
getent passwd

Mental Model

Think in layers: System → Service → Deploy → Human. Each layer should have its own identity. If one layer is compromised, the others must survive.

Production Checklist

  • Every service has its own user
  • No login shells for service users
  • No 777 permissions anywhere
  • Secrets readable only by service user
  • Sudo limited to minimal commands