Page 1 of 1

[solved] increase ulimit -n for user

Posted: 2018/05/22 15:05:47
by ecodinom

I have a full up-to-date centos 7 machine where I want to increase the ulimit -n value to 256 (now is set to 100). This is the output of my ulimit -a

Code: Select all

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 14602
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 100
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 40
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
This is what I tried so far:

- setting the value via ulimit -n 256, which works for the root user but not for regular users
- editing the /etc/security/limits.conf file, which again has effect only for the root user
- editing the /etc/systemd/user.conf file, does not seem to have any effect

any suggestion on what is the correct procedure?

Re: increase ulimit -n for user

Posted: 2018/05/22 15:46:09
by TrevorH
Is this for a task run by systemd? If so you want to add to the unit file. Use man systemd.exec and look for LimitNOFILE= in a table along with all the other things that can be specified.

Re: increase ulimit -n for user

Posted: 2018/05/22 16:41:22
by ecodinom
this is for a nodejs app, which i run by a command like node app.js.

After further investigation I think the problem arises because I'm running my app via ssh, and ssh does not respect ulimit "normal" values. BTW, I only have SSH access, so the question becomes: how to increase ulimit -n in a ssh shell?

Re: increase ulimit -n for user

Posted: 2018/05/22 17:50:32
by ecodinom
Just to add some other info, it seems the the ulimit -n value for the root user mirrors what you put in /etc/security/limits.conf.
So if I put

Code: Select all

* soft nofile 8291
* hard nofile 8291
the root user will actually get a ulimit -n value equal to 8291, while all other users wont.

I have no idea why this happens, btw

Re: increase ulimit -n for user

Posted: 2018/05/23 06:14:22
by ecodinom
Found it.

I missed the limits.d folder in /etc/security, where a file for each users stores user's values, e. g. /etc/security/limits.d/user1.conf stores values for user1.