Skip to content
Log In Sign Up info@muvcloud.com

Check the Current Limits

ulimit -a
ulimit -n
ulimit -Hn

ulimit -a lists every limit of the current shell. ulimit -n shows the soft limit for open files, often 1024, and ulimit -Hn the hard limit, which is usually much higher. These values apply to the shell and to every program you start from it.

OptionLimit
-nOpen files
-uProcesses per user
-sStack size
-cCore file size
-vVirtual memory

Soft and Hard Limits

The soft limit is the one enforced. A process may raise its own soft limit up to the hard limit, which is the ceiling; only root can raise the hard limit. In a shell:

ulimit -n 4096

This raises the soft limit for this session only, and only up to the hard limit.

What Too Many Open Files Means

Every open file, network connection, and pipe uses one file descriptor. A web server, database, or proxy with many clients reaches 1024 quickly, and new connections then fail with "Too many open files" in its log. The fix has three steps: find the process, read its real limit, and raise the limit where that process gets it.

Check a Running Process

A shell's ulimit tells you nothing about a service started at boot. Read the limits of the process itself:

pgrep -o nginx
cat /proc/1234/limits
sudo ls /proc/1234/fd | wc -l

Replace 1234 with the process ID from the first command. In /proc/PID/limits, the line "Max open files" shows the soft and hard value; the last command counts the descriptors the process holds now. lsof shows what those descriptors are.

Raise the Limit for a systemd Service

Services started by systemd do not read /etc/security/limits.conf. Set the limit in the unit with a drop-in:

sudo systemctl edit nginx.service

Add these lines, save, and restart the service:

[Service]
LimitNOFILE=65535
sudo systemctl restart nginx
systemctl show nginx.service -p LimitNOFILE

Check /proc/PID/limits again for the new process ID. Some programs also cap themselves in their own configuration, so read the application's documentation as well. Drop-ins are explained in systemd unit files. A default for all services can be set with DefaultLimitNOFILE in /etc/systemd/system.conf, but a per-service setting is easier to follow.

Raise the Limit for Login Sessions

For users who log in over SSH or switch with su, limits come from /etc/security/limits.conf or a file in /etc/security/limits.d:

deploy  soft  nofile  65535
deploy  hard  nofile  65535

The pam_limits module applies them at login, so log out and back in, then check with ulimit -n. A * in the first column means all users. On Debian and Ubuntu, * and group lines do not apply to root; a limit for root needs a line that names root.

The process starts fromSet the limit in
Your SSH sessionlimits.conf
A systemd serviceA drop-in file
A Docker container--ulimit option

The System-Wide Ceiling

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

file-max is the number of open files the kernel allows in total; file-nr shows three numbers: the handles allocated now, the allocated but unused ones (0 on current kernels), and the maximum. On a 64-bit server the default is very large and is rarely the limit you hit. If you do need to change it, put fs.file-max in a file under /etc/sysctl.d and load it with sudo sysctl --system.

When Raising Is Not the Fix

If the descriptor count of a process grows steadily for hours and never falls, the application is leaking them, for example by opening files or connections without closing them. A higher limit only delays the error. Restart the service to recover, and report or fix the leak. Memory use is worth watching at the same time; see how to check memory usage.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations