Raise the Open Files Limit with ulimit -n

ulimit -n shows or changes the file-descriptor limit of the current shell, fixing 'Too many open files' errors for servers started from that shell.

LinuxrlimitulimittuningMedium risk
Run `ulimit -n` to see the current soft limit and `ulimit -n 4096` to raise it for the current shell session (capped by the hard limit from `ulimit -Hn`).

01Command

Command
$ ulimit -n 4096

02What it does

RLIMIT_NOFILE is one greater than the highest usable file descriptor, and each socket, pipe, or open file consumes one, so long-running daemons exhaust it with the default 1024 soft limit. ulimit -n sets the soft limit only, and it cannot exceed the hard limit (raise soft and hard together with `ulimit -n 4096 -Hn` if permitted). Per-shell changes do not affect already-running services — for systemd services set LimitNOFILE= in the unit, and for logins use /etc/security/limits.conf.

03Risk

RiskMedium risk
RequirementsShell builtin (bash/zsh); soft limits are capped by the hard limit, which is configured in /etc/security/limits.conf or systemd unit LimitNOFILE.

04Undo

Undo
$ ulimit -n 1024

05Sources

  • getrlimit(2)/setrlimit(2) - get/set resource limits
    man7.org Linux man-pages · technical · 2026-09-17
    Evidence: RLIMIT_NOFILE specifies a value one greater than the maximum file descriptor number that can be opened by this process; limits have a soft value (enforced) and a hard value (ceiling for the soft).

Last verified: 2026-09-17 · Category: System & Settings