In this lesson, you will learn how to stabilize your Linux system by preventing a single user from consuming excessive resources through the /etc/security/limits.conf file.
Understanding Resource Constraints
In a multi-user Linux environment, a single user—whether by accident or malice—could launch too many processes or open too many files, potentially crashing the system. To prevent this, Linux administrators use limits.conf to enforce "ceilings" on what a specific user or group can do during a session.
Soft vs. Hard Limits
The system differentiates between two types of limits:
- Soft Limits: These act as a warning threshold. A user can temporarily exceed this limit, but the system will notify them or prevent further expansion once the cap is hit.
- Hard Limits: These are the absolute, non-negotiable ceilings. Even a root user cannot override these for a process once they are set, and a standard user cannot increase them.
Configuring the Limits
The configuration file is located at /etc/security/limits.conf. Entries follow a specific syntax: <domain> <type> <item> <value>.
For example, to ensure that a developer named alice cannot open more than 100 concurrent processes and cannot have more than 50 open file descriptors, you would add these lines to the file:
alice soft nproc 100
alice hard nproc 120
alice soft nofile 50
alice hard nofile 50
nproccontrols the number of processes.nofilecontrols the number of open file descriptors.
These changes take effect the next time the user logs into the system. It is important to note that these limits are enforced by the pam_limits.so module, which is part of the Pluggable Authentication Modules (PAM) stack. If you ever find your system locking out processes unexpectedly, checking this file is your first step in troubleshooting resource allocation.
By setting these boundaries, you create a more predictable environment where one user’s heavy workload cannot starve the rest of the system of essential CPU or memory resources.
Key Takeaway: Use /etc/security/limits.conf to establish hard and soft boundaries on user processes and file descriptors to ensure system-wide stability.