Setup "open files" limit in Linux per user. Cannot setup more than 1024

10,877

Solution 1

I suspect runuser doesn't go through PAM's "login" process that applies limits.conf, or maybe pam_limits.so is disabled. In Debian, at least, /etc/pam.d/su has pam_limits.so commented out so that the limits are inherited from the user running su.

Solution 2

To increase open file limit for certain user on CentOS 5.5 Linux:

1 - in file '/etc/security/limits.conf' add: - http://gerardnico.com/wiki/linux/limits.conf

...
# seed osuser - extended max number of open files
seed    hard    nofile    10240

# End of file

2 - in file '/etc/profile' or in '/home/seed/.bash_profile' add:

if [ $USER = "seed" ]; then
        ulimit -n 10240
fi
Share:
10,877

Related videos on Youtube

Andrey Zentavr
Author by

Andrey Zentavr

Updated on September 17, 2022

Comments

  • Andrey Zentavr
    Andrey Zentavr over 1 year

    I try to increase open file limit for certain user on CentOS 5.5 Linux. I added a new line to /etc/security/limits.conf:

    seed     hard    nofile          10240
    

    Then do test:

    runuser -s /bin/bash - seed -c "ulimit -S -c 0>/dev/null 2>&1; ulimit -a"
    0
    core file size          (blocks, -c) 0
    data seg size           (kbytes, -d) unlimited
    scheduling priority             (-e) 0
    file size               (blocks, -f) unlimited
    pending signals                 (-i) 8185
    max locked memory       (kbytes, -l) 32
    max memory size         (kbytes, -m) unlimited
    open files                      (-n) 1024
    pipe size            (512 bytes, -p) 8
    POSIX message queues     (bytes, -q) 819200
    real-time priority              (-r) 0
    stack size              (kbytes, -s) 10240
    cpu time               (seconds, -t) unlimited
    max user processes              (-u) unlimited
    virtual memory          (kbytes, -v) unlimited
    file locks                      (-x) unlimited
    

    And as you can see - open file limit is still 1024. If I set up the limit as 1000, it will be applied. So, I cannot setup the limit more than 1024.

    How can I do that?? I need to set up the settings only for 1 user, not system-wide.

    • Chris Nava
      Chris Nava over 13 years
    • Zoredache
      Zoredache over 13 years
      @Chris Nava, That is nice in theory, but there are many services that will not reliably operate given that limit. Also 1024 isn't an OS limit is a resource limit placed on accounts.
    • MastaJeet
      MastaJeet over 13 years
      1024 isn't a lot of open file nowadays.
  • Andrey Zentavr
    Andrey Zentavr over 13 years
    [root@seedbox01 ~]# cat /etc/passwd | grep seed seed:x:501:501::/home/seed:/bin/bash
  • Andrey Zentavr
    Andrey Zentavr over 13 years
    [root@seedbox01 ~]# cat /etc/pam.d/runuser #%PAM-1.0 auth sufficient pam_rootok.so session optional pam_keyinit.so revoke session required pam_limits.so session required pam_unix.so
  • Andrey Zentavr
    Andrey Zentavr over 13 years
    Suggestion #1 did not helped me, but #2 - yes.
  • Matthew Ife
    Matthew Ife over 10 years
    This is definitely the reason. I've deleted my answer as you were first :).