25

I have /etc/security/limits.conf, that seems not been applied:

a soft nofile 1048576 # default: 1024 a hard nofile 2097152 a soft noproc 262144 # default 128039 a hard noproc 524288 

Where a is my username, when I run ulimit -Hn and ulimit -Sn, it shows:

4096 1024 

There's only one other file in the /etc/security/limits.d that the content is:

scylla - core unlimited scylla - memlock unlimited scylla - nofile 200000 scylla - as unlimited scylla - nproc 8096 

I tried also append those values to /etc/security/limits.conf then restarting, and do this:

echo ' session required pam_limits.so ' | sudo tee -a /etc/pam.d/common-session 

but it didn't work. My OS is Ubuntu 17.04.

1

2 Answers 2

22

https://superuser.com/questions/1200539/cannot-increase-open-file-limit-past-4096-ubuntu/1200818#_=_

There's a bug since Ubuntu 16 apparently.

Basically:

  1. Edit /etc/systemd/user.conf for the limit on user services, and add DefaultLimitNOFILE=1048576.
  2. Edit /etc/systemd/system.conf for the limit on system services and things they create, and add DefaultLimitNOFILE=2097152.

You need to edit both files.

To set a separate soft and hard limit, specify them like soft:hard, eg 4096:16384.

Credit goes to @mkasberg.

3
  • 1
    After these settings, do we need restart? Commented Jan 23, 2018 at 17:22
  • 2
    Yes, a restart was required when I tried it. Commented Jan 24, 2018 at 13:05
  • this works to set ulimit values, but one thing to notice: systemd has only "infinity" value to set ulimit to "unlimited", there is apparently no "unlimited" value in systemd 252 (252-18.el9) Commented Dec 6, 2023 at 16:52
17

It is recommended to create /etc/systemd/*.d/ directories instead of editing /etc/systemd/system.conf and /etc/systemd/user.conf directly.

  1. Create a new file /etc/systemd/system.conf.d/limits.conf with these contents:

    [Manager] DefaultLimitNOFILE=1048576:2097152 DefaultLimitNPROC=262144:524288 
  2. Run systemctl daemon-reexec as root.

  3. Logout and login again.

  4. Check your new limits with either ulimit -a or ulimit -n and ulimit -u for max open files and max processes, respectively.

Refer to the systemd-system.conf manpage for details.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.