Why it cannot get past 4096 max open files for non-root user?

I can't seem to increase the nofile limit for non-root users on Ubuntu 14.04, despite following every StackExchange answer related to this problem. So far I have:

$ cat /etc/security/limits.d/custom.conf
@www-data hard nofile 50000
@www-data soft nofile 50000
# even tried specifying the username directly:
myuser hard nofile 50000
myuser soft nofile 50000

$ grep 'limits' /etc/pam.d/common-session*
/etc/pam.d/common-session:session required        pam_limits.so
/etc/pam.d/common-session-noninteractive:session required        pam_limits.so

$ cat /proc/sys/fs/file-max
101232

Rebooted, logged in, and:

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

There still somehow seems to be a limit of 4096 max for non-root users.


Solution 1:

Using Ubuntu 14.04 I got the described hard limit:

user@notebook:~$ ulimit -Hn 4096  

I could lower it using ulimit, but not increase it, just as the question describes it. As ulimit's manual describes:

only root can increase the hard limit

So I tried to set a higher limit in /etc/security/limits.conf like this:

user hard nofile 9999 

and a fresh login like ssh localhost -l user gave me the new limit:

user@notebook:~$ ulimit -Hn 9999

Hope this works for you, too.

Solution 2:

This article, I think addresses your issue.

Basically you should use ulimit command to increase the available resources.

For example:

Use the following command command to display maximum number of open file descriptors:

cat /proc/sys/fs/file-max

To see the hard and soft values, issue the command as follows:

# ulimit -Hn
# ulimit -Sn

To see the hard and soft values for httpd or oracle user, issue the command as follows:

# su - username

To fix the number of maximum files, you can increase the maximum number of open files by setting a new value in kernel variable /proc/sys/fs/file-max as follows (login as the root):

# sysctl -w fs.file-max=100000

Above command forces the limit to 100000 files. You need to edit /etc/sysctl.conf file and put following line so that after reboot the setting will remain as it is. To do that, append a config directive as follows:

fs.file-max = 100000

Save and close the file. Users need to log out and log back in again to changes take effect or just type the following command:

# sysctl -p

Verify your settings with command:

# cat /proc/sys/fs/file-max

or:

# sysctl fs.file-max

The above procedure sets system-wide file descriptors (FD) limits, however you can limit httpd (or any other users) user to specific limits by editing /etc/security/limits.conf file by editing /etc/security/limits.conf and set the limits as follows:

httpd soft nofile 4096
httpd hard nofile 10240

Then check them by:

# su - httpd
$ ulimit -Hn
$ ulimit -Sn

If you've got the problem on other Linux distributions, check the /etc/pam.d/login and make sure you've got pam_limits.so enabled, e.g.

session required pam_limits.so

Solution 3:

If it is a Service, you can try to set the limit in /etc/systemd/system/{ServiceName}.service add LimitNOFILE=65536