Operations 8 min read

How to Raise Linux Open‑File Limits with ulimit, PAM, and sysctl

This guide explains why Linux limits the number of open files, shows how to view current limits, and provides three practical methods—using the ulimit command, editing PAM limits, and adjusting sysctl settings—to permanently increase both soft and hard file‑descriptor limits.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How to Raise Linux Open‑File Limits with ulimit, PAM, and sysctl

When a file is opened, the operating system assigns a numeric file handle stored in a reserved kernel memory area; the size of this area determines how many files can be opened simultaneously. Linux imposes per‑process and system‑wide limits to prevent resource exhaustion.

Why Limit Open Files?

The OS needs memory to track each file descriptor, so the total number of open files is constrained. Limiting the count also protects against denial‑of‑service attacks that could exhaust resources.

Viewing Current Limits

System‑wide maximum:

cat /proc/sys/fs/file-max
180965

Per‑session soft limit (default 1024):

ulimit -a | grep open
open files                (-n) 1024

Hard limit (default 4096):

ulimit -Hn
4096

Method 1 – Using ulimit

The built‑in ulimit command changes limits for the current shell and its children. -a – display all limits -n – set the maximum number of open file descriptors -H and -S – specify hard or soft limits respectively

Example: increase the soft limit to 2048. ulimit -n 2048 To make the change persistent, append the command to ~/.bashrc or ~/.bash_profile:

echo "ulimit -n 2048" >> ~/.bashrc

Method 2 – Editing PAM Limits

Configure the pam_limits module via /etc/security/limits.conf. Each line contains four fields: domain (user, group, or *), type (hard/soft), item (e.g., nofile), and value.

Example to set global limits:

* hard nofile 20000
* soft nofile 15000

Enable the module by adding the following line to /etc/pam.d/login:

session    required   pam_limits.so

Method 3 – Modifying sysctl

View the kernel parameter:

cat /proc/sys/fs/file-max
180965

Temporarily raise it: echo 1000000 > /proc/sys/fs/file-max For a permanent change, add the line to /etc/sysctl.conf and reload:

echo "fs.file-max = 1000000" >> /etc/sysctl.conf
sysctl -p

Summary

The total number of file descriptors used by all processes cannot exceed /proc/sys/fs/file-max. Each process is limited by the soft nofile value, which cannot surpass its hard limit. Using ulimit, PAM limits, or sysctl allows administrators to raise these thresholds safely.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

linuxpam_limitsulimitsystem limits
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.