8

Using RHEL7 with systemd

Do you have to use a specific file name convention in /etc/security/limits.d (besides the file ending in .conf)? There is a file in this directory called 20-nproc.conf. So if I wanted to raise the open file limit for USER1 how would I name this .conf file? Does that first number matter? ie. 20 in the .conf file 20-nproc.conf

And should I create this .conf in /etc/security/limits.d directory since /etc/security/limits.conf states:

Also note that configuration files in /etc/security/limits.d directory,
which are read in alphabetical order, override the settings in this
file in case the domain is the same or more specific.
...

Can I create a .conf file called 30-USER1-nofile.conf

which contains

USER1   soft   nofile   6000
USER1   hard   nofile   6000
3
  • this sounds like a RHEL specific thing? I use SUSE/SLES and for that it's just /etc/security/limits.conf where you could just do USER1 hard nofile 6000 per the comment section detailing the format in the beginning of the limits.conf file.
    – ron
    May 17, 2017 at 15:39
  • Are you using systemd? I was just reading that for systems using systemd you have to specify the open file limit in the service unit file.
    – jes516
    May 17, 2017 at 16:21
  • @jes516 that's the setting for a service. If you're talking regular user sessions, then use /etc/security/limits.d (i.e., pam_limits). Mar 18, 2021 at 15:16

2 Answers 2

6

The conf files in the directory are ascibetically sorted, and each sourced in order.

The numbering is a convention to ensure that all sorting methods agree, and to make inserting new rules easy when it comes to placement.

Do not, do not, edit the limits.conf file, as this is now error-attracting as it is just a bad policy in general (the reasons for which weren't as obvious back then).

5
  • 2
    i was able to change the open file limit starting the process with systemd using LimitNOFILE=10000 in the [Service] section
    – jes516
    Jul 19, 2017 at 20:34
  • That's a fine solution, if a little non-portable. As long as you're on a system inflicted with systemd, and the systemd folks don't change it, you should be okay. Jul 21, 2017 at 22:32
  • Is it [Manager] or [Service] section? It seems to be Manager on CentOS Linux release 7.5
    – Goblinhack
    Apr 4, 2019 at 20:15
  • Alphabetically sorted, but only files ending with .conf. And +1 for the advice not to edit limits.conf directly, but drop in files to /etc/security/limits.d. Mar 18, 2021 at 15:19
  • Yeah. the .d directory has been a paradigm since like EL5, but conversion is an uphill battle. Mar 24, 2021 at 5:06
0

from trial and error on a fedora32 box, it seems that the drop-in file must be named *.conf

5
  • See man pam_limits: "By default limits are taken from the /etc/security/limits.conf config file. Then individual *.conf files from the /etc/security/limits.d/ directory are read." Jun 4, 2020 at 15:54
  • Notice also that the OP suggested such a filename: 30-USER1-nofile.conf
    – Jeff Schaller
    Jun 4, 2020 at 18:59
  • Can you address the rest of the question? "Does that first number matter?"
    – Jeff Schaller
    Jun 4, 2020 at 19:00
  • in general these drop-in directories (the ones ending in .d) are loaded in alphabetical order, hence the numbering; that will matter only if several files try to define the same setting Jun 6, 2020 at 4:53
  • "Does that first number matter?" -> a little: It dictates the order in which they're read into the parser (search for 'ascibetically' from three years before you asked). So yeah, important in theory but it's not often a big deal. Jun 17, 2021 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.