Linux – ulimit for root keeps resetting

centoscentos6linuxulimit

Using CentOS 6.6

In /etc/security/limits.conf I have set the following:

* soft nofile 65535
* hard nofile 65535
root soft nofile 65535
root hard nofile 65535

In etc/security/limits.d/90-nproc.conf I have set this:

*          soft    nproc     65535
root       soft    nproc     unlimited
*          soft    nofile    65535
root       soft    nofile    65535
*          hard    nofile    65535
root       hard    nofile    65535

Yet for some reason when I log out and log in to SSH as root (passwordless login using ssh key):

[root@server ~]# ulimit -Hn
4096
[root@server ~]# ulimit -Sn
1024

How do I make ulimit persist?

Best Answer

Turns out it was because I was using UsePAM no in /etc/ssh/sshd_config.

For some reason, every tutorial online recommends disabling PAM in order to disable password logins without a key. After doing some research, it seems this is terrible advice and I'm not sure why it is recommended by so many tutorials.

With PAM disabled, pam_limits module is never run causing the limits to never be read from the limits.conf file.