How to Fix "Too Many Open Files" Errors on Linux

"Too many open files" errors occur when a process exceeds the maximum number of file descriptors it's allowed to have open simultaneously — a common issue for busy web servers, databases, or applications handling many concurrent connections.

Why This Happens

Linux limits how many files (including network sockets, which count as file descriptors) a process can have open at once — default limits are often conservative, set for typical desktop use rather than high-concurrency server workloads.

Checking Current Limits

ulimit -n

Shows the current soft limit for the current shell session — often defaults to 1024, frequently too low for a busy production server.

Checking a Specific Process's Actual Open File Count

ls /proc/PID/fd | wc -l

Compare against the configured limit to confirm the process is genuinely approaching or hitting its limit.

Checking System-Wide Limits

cat /proc/sys/fs/file-max

Increasing Limits Temporarily (Current Session Only)

ulimit -n 65536

Increasing Limits Permanently (System-Wide)

sudo nano /etc/security/limits.conf
*    soft    nofile    65536
*    hard    nofile    65536

Increasing Limits for a Specific systemd Service

sudo systemctl edit nginx
[Service]
LimitNOFILE=65536

systemd services don't automatically inherit /etc/security/limits.conf settings — they need this explicit override for their specific unit.

Reloading and Restarting the Service

sudo systemctl daemon-reload
sudo systemctl restart nginx

Verifying the New Limit Applied

cat /proc/PID/limits | grep "Max open files"

Increasing the System-Wide Maximum (If Needed)

sudo nano /etc/sysctl.conf
fs.file-max = 2097152
sudo sysctl -p

Rarely needed unless you're running an exceptionally high number of concurrent processes/connections across the entire system, not just one specific service.

Application-Level Considerations

If a specific application is genuinely leaking file descriptors (opening files/connections without properly closing them), raising limits only delays the problem rather than fixing the underlying leak — investigate whether the growth in open files is expected for your actual load, or indicates an application bug.

Common Errors

Limit increase in limits.conf doesn't seem to apply — verify you're checking the limit for a genuinely new session/process started after the change, and remember systemd services need their own explicit override, not just the global limits.conf setting.

Continue Reading

Browse more articles in Troubleshooting & FAQ.

  • too many open files error, ulimit nofile, increase file descriptor limit, linux open files limit
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Website Down? A Step-by-Step Troubleshooting Checklist

When a website goes down, working through checks in the right order saves critical time. This...

VPS Unreachable/Can't Connect via SSH: Troubleshooting Guide

Losing SSH access to your VPS is stressful, but most causes are fixable without needing to...

How to Fix "No Space Left on Device" Errors

A full disk can silently break databases, log writing, package installations, and web...

How to Diagnose and Fix High CPU Usage on a VPS

Sustained high CPU usage can slow down your entire server and every application running on it....

How to Diagnose and Fix Out of Memory (OOM) Errors

When a Linux server runs out of available RAM, the kernel's OOM (Out of Memory) killer forcibly...