Ubuntu: How do I increase the open files limit for a non-root user?
Channel: Roel Van de Paar
Date: 17/06/2019

Ubuntu: How do I increase the open files limit for a non-root user?


Question: This is happening on Ubuntu Release 12.04 (precise) 64-bit Kernel Linux 3.2.0-
25-virtual
I'm trying to increase the number of open files allowed for a user. This is for
my eclipse java application where the current limit of 1024 is not enough.
According to the posts I've found so far, I should be able to put lines into
/etc/security/limits.conf like this:
soft nofile 4096
hard nofile 4096
to increase the number of open files allowed for all users.
But that's not working for me and I think the problem is not related to that
file.
For all users, the default limit is 1024, regardless of what is in /etc/
security/limits.conf (I rebooted after changing that file)
$ ulimit -n
1024
Now, despite the entries in /etc/security/limits.conf I can't increase that:
$ ulimit -n 2048
-bash: ulimit: open files: cannot modify limit: Operation not permitted The
weird part is that I can change the limit downwards, but can't change it
upwards - even to go back to a number which is below the original limit:
$ ulimit -n 800
$ ulimit -n
800

$ ulimit -n 900

-bash: ulimit: open files: cannot modify limit: Operation not permitted
As root, I can change that limit to whatever I want, up or down. It doesn't
even seem to care about the supposedly system-wide limit in /proc/sys/fs/file-
max
# cat /proc/sys/fs/file-max
188897

# ulimit -n 188898
# ulimit -n
188898
But even I get eclipse to run as root, my application still crashes because of
"Too Many Open File" exception!
So far, I haven't found any way to increase the open files limit for a non-root
user.
How should I properly do this? I have looked at several other posts but no
luck!

Solutions Sample (Please watch the whole video to see all solutions, in order of how many people found them helpful):

== This solution helped 126 people ==
The ulimit command by default changes the HARD limits, which you (a user) can
lower, but cannot raise.
Use the -S option to change the SOFT limit, which can range from 0-{HARD}.
I have actually aliased ulimit to ulimit -S, so it defaults to the soft limits
all the time.
alias ulimit='ulimit -S'
As for your issue, you're missing a column in your entries in /etc/security/
limits.conf.
There should be FOUR columns, but the first is missing in your example.
* soft nofile 4096
* hard nofile 4096
The first column describes WHO the limit is to apply for. '*' is a wildcard,
meaning all users. To raise the limits for root, you have to explicitly enter
'root' instead of '*'.
You also need to edit /etc/pam.d/common-session* and add the following line to
the end:
session required pam_limits.so

== This solution helped 18 people ==
If you use soft and hard limits on a per user basis you can use something like:
su USER --shell /bin/bash --command "ulimit -n"
to check wether your settings are working for that specific user or not.

With thanks & praise to God! With thanks to the many people who have made this project possible! | Content (except music & images) licensed under cc by-sa 3.0 | Music: https://www.bensound.com/royalty-free-music | Images: https://stocksnap.io/license & others | With thanks to user lornix (https://askubuntu.com/users/76275), user Layke (https://askubuntu.com/users/91462), user landroni (https://askubuntu.com/users/227922), user Jr. (https://askubuntu.com/users/862063), user Jeroen Teeuwen (https://askubuntu.com/users/192275), user iCode (https://askubuntu.com/users/76286), user David Foerster (https://askubuntu.com/users/175814), and the Stack Exchange Network (http://stackoverflow.com/questions/162229). Trademarks are property of their respective owners. Disclaimer: All information is provided "AS IS" without warranty of any kind. You are responsible for your own actions. Please contact me if anything should be amiss at Roel D.OT VandePaar A.T gmail.com.