Roman Cheplyaka

Increase the open files limit on Linux

Published on March 26, 2017; tags: Linux

Each process on Linux has several limits associated with it, such as the maximum number of files it can open simultaneously. You can find out your current open files limit by running

ulimit -Sn # soft limit; can be raised up to the hard limit
ulimit -Hn # hard limit

To see all limits, run

ulimit -Sa # soft limits
ulimit -Ha # hard limits

The way you can adjust these limits depends on the particular Linux system (e.g. whether it is systemd-based, and possibly even on the version of systemd) and on the way you logged into the system (via console, gdm, lightdm etc.)

Here I describe a few steps that can help you to increase the open files limit. It’s hard to predict which steps will be relevant, but if you follow all of them, there’s a good chance you will succeed.

Similar instructions should work for other limits, too.

PAM

Edit the file /etc/security/limits.conf and add the following lines:

* - nofile 20000

where 20000 is the desired limit. The * means all users, and the - means set both soft and hard limits. See limits.conf(5).

You may want to replace the * with a specific user name. Moreover, to change the limits for root, you may need to write root instead of *.

Check that there are no conflicting declarations under /etc/security/limits.d/*.conf, as those files take precedence.

Next, to ensure that these settings are applied, locate the file under /etc/pam.d that corresponds to your login method (/etc/pam.d/login for console, /etc/pam.d/lightdm for lightdm and so on) and add the following line unless it is already there:

session required pam_limits.so

For the changes to take effect, it should be sufficient to re-login.

On Fedora 25, the PAM settings alone seemed to work for the console login but not for the lightdm login.

systemd

If you are on a systemd-based system, try editing both /etc/systemd/system.conf and /etc/systemd/user.conf and adding the following line under the [Manager] section (see systemd-system.conf(5)):

DefaultLimitNOFILE=20000

Then reboot the system.

I found out about this setting from a comment by Ewan Leith, but changing user.conf alone didn’t work for me; I had to change both user.conf and system.conf.