I configured nproc limit for a user in limits.conf, it isn’t working

This post applies to RHEL 6 and RHEL 7. I changed the nproc limit for a user to 16383 in /etc/security/limits.conf.

cat >>  /etc/security/limits.conf
username         soft    nproc           16383

When I checked it with ulimits -n, it isn’t working.

su - username 
ulimits -a
1024

This is because, to prevent a fork bomb, the default limits for all users except root is set to 1024 in RHEL 6. The setting is in /etc/security/limits.d/90-nproc.conf which overrides /etc/security/limits.conf.

RHEL 6

cat /etc/security/limits.d/90-nproc.conf
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.

*          soft    nproc     1024
root       soft    nproc     unlimited

RHEL 7

cat /etc/security/limits.d/20-nproc.conf
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.

*          soft    nproc     4096
root       soft    nproc     unlimited

The solution is to create a file in /etc/security/limits.d/ that will override the limit for the user.

cat  <<EOF > /etc/security/limits.d/99-username-limits.conf
# username user limits file
username         soft    nproc           16383
EOF
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s