linux,

How to increase the open files limit in Linux

Jan 16, 2022 · 1 min read · Post a comment

The default open files (nofile) limit is 1024. Let’s see how we could confirm and increase it on user and system-wide level.

Prerequisites

  • Shell environment

Check and modify open files limit on user level

Step 1. Check open files limit on current user.

ulimit -n
1024

Step 2. Check soft limit.

ulimit -Sn
1024

Step 3. Check hard limit.

ulimit -Hn
1048576

Note(s):

  • soft limits refer the actual limit value that affects processes, and it can be changed by them over time within the range of [0, hard limit].
  • hard limits are the maximum values for soft limits, serve as a security purpose and are kernel-enforced. It can be raised only by root. A non-root user could only decrease it from the currently set one.

Step 4. Modify open files limit for all users, by adding the following lines to /etc/security/limits.conf:

*               soft    nofile          4096
*               hard    nofile          4096

Note(s): If you want to configure custom limit for the root user, replace * with root. The same goes for any other users or groups.

Check and modify open files limit on system-wide level

Step 1. Check open files limit system-wide.

cat /proc/sys/fs/file-max

Output:

65536

Step 2. Increase the open files limit available to the whole server, by adding the following line to /etc/sysctl.conf:

fs.file-max = 1631956

Step 3. Apply changes.

sysctl -p

Conclusion

Personally, I’ve never experienced any issues while messing around with soft/hard limits, but if you have any interesting story to share, please leave a comment below. On a side note, follow our official channel on Telegram.