具体的 limit 配置文章见 /etc/security/limits.conf 详解与配置
问题
按照上面的配置好了之后,我们进行设置登录到服务器,我发现是配置没有生效的,但是我使用 su - root 之后,发现配置是生效的。 很怪异。
设备环境: Centos6.
问题原因
主要是 Centos6 的原因,我们排查到 sshd 服务的 PAM 模块是没有开启的,而/etc/security/limits.conf
文件实际是 Linux PAM(插入式认证模块,Pluggable Authentication Modules)中 pam_limits.so
的配置文件,我们没有开启 PAM 模块,最终也就没有读取到 /etc/security/limits.conf
的内容。 而 su 进行切换的时候使用的是 终端tty登陆(默认使用PAM模块),
解决办法
在 /etc/ssh/sshd_config
将 UsePAM no
更改为 UsePAM yes
, 然后重启 sshd 服务。