I'm on Ubuntu 17.04. Trying to increase the open file limit, and none of the instructions I've found online are working. I can go up to 4096, but can't go past that.
$ ulimit -n
1024
$ ulimit -n 4096
$ ulimit -n
4096That works. This doesn't:
$ ulimit -n 4097
bash: ulimit: open files: cannot modify limit: Operation not permittedIt appears to be because of the hard limit:
$ ulimit -Hn
4096I've tried adding these lines to /etc/security/limits.conf:
* hard nofile 65535
* soft nofile 65535
root soft nofile 65535
root hard nofile 65535Also added this line to /etc/pam.d/common-session and /etc/pam.d/common-session-noninteractive:
session required pam_limits.soSince doing that, I've rebooted my computer. Changes to limits.conf don't seem to affect anything. The hard limit is still stuck at 4096, preventing me from going any higher. How do I increase my open files limit?
Here's some additional config info:
$ cat /proc/sys/fs/file-max
1624668 5 Answers
OK, I finally figured this out. The limits I was setting in /etc/security/limits.conf were indeed being applied, but not to the graphical login. This can be verified from a terminal window:
$ ulimit -n
4096
$ su mkasberg
Password:
$ ulimit -n
65535More 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=65535That change works, but only affecting the soft limit. (Leaving us capped with a hard limit of 4096 still.) In order to affect the hard limit, we must modify /etc/systemd/system.conf with the same changes.
The changes I made in /etc/pam.d were not necessarily; it's already working, at least on Ubuntu. Also, it was not necessary to add the lines root and * in limits.conf; adding the username alone (mkasberg in my case) was sufficient.
In Summary
If you want to increase the limit shown by ulimit -n, you should:
Modify
/etc/systemd/user.confand/etc/systemd/system.confwith the following line (this takes care of graphical login):DefaultLimitNOFILE=65535Modify
/etc/security/limits.confwith the following lines (this takes care of non-GUI login):mkasberg hard nofile 65535 mkasberg soft nofile 65535Reboot 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.confwith these contents:[Manager] DefaultLimitNOFILE=65535run
systemctl daemon-reexecas 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=65535or better here:
$ grep NOFILE /etc/systemd/system.conf.d/limits.conf DefaultLimitNOFILE=65535shell 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 65535After altering the settings in the above files, reboot and then check the limits with:
ulimit -n -Hn -Sn
edit /etc/systemd/system/sonar.service
add these two line under Service
[Service]
LimitMEMLOCK=infinity
LimitNOFILE=65535
- systemctl daemon-reload
- systemctl restart sonar
this works for me.
Using Ubuntu 17.04 I got the described hard limit:
:~$ ulimit -Hn
4096I could lower it using ulimit, but not increase it, just as the question describes it. ulimit manual describes:
only root can increase the hard limit.
So I tried to set a higher limit in /etc/security/limits.conf like this:
user hard nofile 9999and a fresh login like ssh localhost -l user gave me the new limit:
:~$ ulimit -Hn
9999I hope this works for you too.