Cannot Increase open file limit past 4096 (Ubuntu)
OK, I finally figured this out. The limits I was setting in /etc/security/limits.conf
were being applied, but they were not being applied to the graphical login. This can be verified like this from a terminal window:
$ ulimit -n
4096
$ su mkasberg
Password:
$ ulimit -n
65535
More research led me to this bug report, which got me pointed in the right direction. In order to modify the limit that is used by the login shell, we need to add the following line to /etc/systemd/user.conf
:
DefaultLimitNOFILE=65535
That change works, but only affects the soft limit. (Leaving us capped with a hard limit of 4096 still.) In order to affect the hard limit also, we must modify /etc/systemd/system.conf
with the same change.
The changes I made in /etc/pam.d
were not necessary. At least on Ubuntu, this is already working. Also, it was not necessary to change settings for root
and *
in limits.conf. Changing limits for mkasberg
was sufficient, at least for my use case.
In Summary
If you want to increase the limit shown by ulimit -n
, you should:
Modify
/etc/systemd/user.conf
and/etc/systemd/system.conf
with the following line (this takes care of graphical login):DefaultLimitNOFILE=65535
Modify
/etc/security/limits.conf
with the following lines (this takes care of non-GUI login):mkasberg hard nofile 65535 mkasberg soft nofile 65535
Reboot your computer for changes to take effect.
No need to change anything in the /etc/security/limits.conf
file, it is ignored if you are using systemd.
(reproducing a modified answer to another question on the network...)
An alternative for those who prefer not to edit the default /etc/systemd/system.conf
and /etc/systemd/user/conf
files:
create a new file
/etc/systemd/system.conf.d/limits.conf
with these contents:[Manager] DefaultLimitNOFILE=65535
run
systemctl daemon-reexec
as rootlogout and login again
check your new limit with
ulimit -n
.
Refer to the systemd-system.conf
manpage for details.
TL;DR I felt the need to concentrate the answers, so they're easier to find. Took me ages to get all the pieces together to make it work correctly ...
There are 2 locations to be considered.
GUI session
$ grep DefaultLimitNOFILE /etc/systemd/system.conf DefaultLimitNOFILE=65535
or better here:
$ grep NOFILE /etc/systemd/system.conf.d/limits.conf DefaultLimitNOFILE=65535
shell environment
$ grep nofile /etc/security/limits.conf user soft nofile 65535 user hard nofile 65535`
or better here:
$ grep nofile /etc/security/limits.d/user.conf user soft nofile 65535 user hard nofile 65535
After altering the settings in the above files, reboot and then check the limits with:
ulimit -n -Hn -Sn