Permanently raising nofile limits in Ubuntu 14.04 LTS

22,541

I increased the number of files limits for everyone this way (segment from /etc/security/limits.conf):

#        - memlock - max locked-in-memory address space (KB)
#        - nofile - max number of open files (Doug: - so Samba will not complain)
* - nofile 16384
#        - rss - max resident set size (KB)
#        - stack - max stack size (KB)

That was on a 12.04 server. However, I tested 100000 on my 14.04 server and it worked fine. (Edit: also checked on 20.04)

~/config/security$ ulimit -n
16384

EDIT: For most applications that is enough, but it doesn't change the default value for root:

# ulimit -n
1024

If the number also needs to be changed for root, then (2020.09.04 - I now use 131,072):

#        - memlock - max locked-in-memory address space (KB)
#        - nofile - max number of open file descriptors
* - nofile 131072
root - nofile 131072
#        - rss - max resident set size (KB)
#        - stack - max stack size (KB)

And so:

$ sudo su
# ulimit -n
131072
Share:
22,541

Related videos on Youtube

w3rthl3ss
Author by

w3rthl3ss

Updated on September 18, 2022

Comments

  • w3rthl3ss
    w3rthl3ss over 1 year

    I cannot seem to figure out what exactly is needed to allow the maximum number of file descriptors to be raised permanently for all users.

    /etc/security/limits.conf:

    root    hard    nofile    1500000
    root    soft    nofile    1000000
    root    hard    nproc     15000
    root    soft    nproc     10000
    *       hard    nofile    1500000
    *       soft    nofile    1000000
    *       hard    nproc     15000
    *       soft    nproc     10000
    

    I have placed the following in the /etc/pam.d/common-session:

    session required pam_limits.so
    

    After a reboot, logging in as any user and issuing ulimit -n resulted in 1024.

    After that, I tried requiring pam_limits.so into every file under /etc/pam.d. Rebooted. Logged in. No such luck.

    If I issue the command ulimit -n 1000000, then check, the limit is set as expected. So, I placed @reboot ulimit -n 1000000 into crontab -e. Rebooted. Logged in. No luck.

    I checked /etc/ssh/sshd_config and PAM is enabled.

    I have tried setting the limits on every reboot with:

    /sbin/sysctl -w fs.file-max=1000000
    /sbin/sysctl -p
    

    No luck.

    I have a server that has a ton of concurrent traffic, and need those limits that high, because it takes the server a very long time to clear out file descriptors. What do I have to do in order to permanently raise the file descriptor limit?

  • w3rthl3ss
    w3rthl3ss about 9 years
    That still had no effect. Did you have to place session require pam_limits.so anywhere?
  • Doug Smythies
    Doug Smythies about 9 years
    No. I just did the edit, as sudo, and re-booted, before the ulimit was 1024 and after the ulimit on my 14.04 test server was 100000.
  • w3rthl3ss
    w3rthl3ss about 9 years
    Simply adjusting /etc/security/limits.conf and reverting everything else back to stock worked. Thanks!
  • Jacob
    Jacob about 7 years
    No need to reboot, just logout/login.
  • Rizwan Patel
    Rizwan Patel almost 7 years
    @w3rthl3ss what does your limit.conf looks like i have same issue and reference purposes
  • w3rthl3ss
    w3rthl3ss almost 7 years
    @RizwanPatel I used the same format as the one in the question.
  • Rizwan Patel
    Rizwan Patel almost 7 years
  • Rizwan Patel
    Rizwan Patel almost 7 years
    @w3rthl3ss any recommendations wanted to change my ulimit from 1864 to 2048 !
  • Doug Smythies
    Doug Smythies almost 7 years
    @RizwanPatel : I do not understand why your ulimit would be 1864. This answer should be what to do. If not, perhaps start a new question, detailing why your new question isn't actually a duplicate of this one. Point us to the new question, and we'll try to help.
  • Rizwan Patel
    Rizwan Patel almost 7 years
    @DougSmythies Sorry my conventional ulimit -u is 1824 and when i apply the changes in limit.conf file and rebooted the server the value remains same !