I have added a line in /etc/security/limits.conf to increase the number of open files.

*    hard nofile 4096
root hard nofile 16384

However when I run ulimit -n it says 1024 which is the default value. I did a logout and login but still see 1024. How can I apply the change?


If you're using bash, ulimit -n will only display the soft limit. To get the hard limit, you need to do ulimit -Hn.

On my system, I see this:

$ ulimit -n
$ ulimit -Hn
| improve this answer | |

Changes made by ulimit command:

$ ulimit -n 4096
$ ulimit -Hn 16384

will apply only for current user and session. In order to make it permanent, you have to modify /etc/security/limits.conf by adding your limits:

* soft nofile 4096
* hard nofile 16384

However, wildcard * won't apply for root user. In order to do so, you have to state it explicitly:

* soft nofile 4096
* hard nofile 16384
root soft nofile 4096
root hard nofile 16384

These limits will be applied after reboot.

If you want to apply changes without reboot, modify /etc/pam.d/common-session by adding this line at the end of file:

session required pam_limits.so

Upon next login you should see updated limits, you can check them (soft and hard limits):

$ ulimit -a
$ ulimit -Ha
| improve this answer | |
  • 2
    I had an issue with this approach which was really strange. I am using Ubuntu 14 and enabled pam_limits.so in /etc/pam.d/common-session. I have configured in /etc/security/limits.conf user x to have hard and soft limits for nofile 64000. sudo -u x then ulimit -a shows me that the changes were not applied. I realized that su and sudo have different pam configurations so in order to make it work properly I needed to enable the pam_limits.so in /etc/pam.d/common-session-noninteractive. If you are wondering what is the use case - I use ansible and sudo to change user. – hahcho Dec 1 '17 at 10:10
  • 1
    For some reason, I had to add it to /etc/pam.d/common-session-noninteractive for it to work. – Sumit Nov 29 '18 at 5:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.