Fixing ulimit: open files: cannot modify limit: Operation not permitted

60,322

Check that /etc/ssh/sshd_config contains:

UsePAM=yes

and that /etc/pam.d/sshd contains:

session    required   pam_limits.so

Still no answer to why 1048576 is max.

The 1048576 seems to be per process. So by having multiple processes this limit can be overcome.

Share:
60,322

Related videos on Youtube

Ole Tange
Author by

Ole Tange

I am strong believer in free software. I do not believe in Santa, ghosts, fairies, leprechauns, unicorns, goblins, and gods. Author of GNU Parallel.

Updated on September 18, 2022

Comments

  • Ole Tange
    Ole Tange over 1 year

    I tested this on different GNU/Linux installations:

    perl -e 'while(1){open($a{$b++}, "<" ,"/dev/null") or die $b;print " $b"}'
    

    System A and D

    The first limit I hit is 1024. It is easily raised by putting this into /etc/security/limits.conf:

    *                hard    nofile          1048576
    

    and then run:

    ulimit -n 1048576
    echo 99999999 | sudo tee /proc/sys/fs/file-max
    

    Now the test goes to 1048576.

    However, it seems I cannot raise it above 1048576. If I put 1048577 in limits.conf it is simply ignored.

    What is causing that?

    System B

    On system B I cannot even get to 1048576:

    echo 99999999 | sudo tee /proc/sys/fs/file-max
    

    /etc/security/limits.conf:

    *                hard    nofile          1048576
    

    Here I get:

    $ ulimit -n 65537
    bash: ulimit: open files: cannot modify limit: Operation not permitted
    $ ulimit -n 65536
    #OK
    

    Where did that limit come from?

    System C

    This system also has the 1048576 limit in limits.conf and 99999999 in /proc/sys/fs/file-max.

    But here the limit is 4096:

    $ ulimit -n 4097
    -bash: ulimit: open files: cannot modify limit: Operation not permitted
    $ ulimit -n 4096
    # OK
    

    How do I raise that to (at least) 1048576?

    (Note to self: Don't do: echo 18446744073709551616 | sudo tee /proc/sys/fs/file-max)

    • Abbadon
      Abbadon over 6 years
      I have exactly the same issue, the limit seems to be 1048576. If I go over I get the following error: bash: ulimit: open files: cannot modify limit: Operation not permitted
    • Time4Tea
      Time4Tea about 4 years
      Hi, I am having a very similar problem. I think it would be very helpful to provide more details on what these different systems are.
  • Jeff Schaller
    Jeff Schaller about 7 years
    If this was really the solution to your own problem, I think it'd be good to draw more of a connection between the problem and the above solution.
  • saladi
    saladi over 5 years
    Re: 1048576 (= 2^10 * 2^10 = 1024^2, for reference). There may be some relevant information in this answer here: stackoverflow.com/a/1213069/2320823
  • Linas
    Linas over 5 years
    What's ssh got to do with it?
  • Time4Tea
    Time4Tea about 4 years
    I agree with @Linas . Sorry, I think the link between the answer and the question is unclear.
  • Arturski
    Arturski about 2 years
    if you are interactions over ssh pam limits need to set the pam module for ssh to include the limits file otherwise activity over ssh will not work