Loading
0

SSH登录报错 Could not set limit for 'nofile': Operation not permitted解决方法
被墙跳转TG:@qianhenetwork QQ 851617266

301免备案跳转微信公众号
腾讯云服务器大促销。
华为服务器


前言:用户反馈创root登录正常,但创建的其他所有用户使用秘钥无法登录,引导用户提供了系统日志,报错pam_limits(sshd:session): Could not set limit for 'nofile': Operation not permitted 字面意思看是limit 与 nofile设置的值不匹配导致,最终引导用户按照本教程处理后正常了。
报错如图

540]: pam_limits(sshd:session): Could not set limit for 'nofile': Operation not permitted
Feb 11 16:45:01 haoka-2 systemd[3210543]: pam_limits(systemd-user:session): Could not set limit for 'nofile': Operation not permitted
Feb 11 16:45:01 haoka-2 systemd[3210543]: pam_unix(systemd-user:session): session opened for user jumpuser01 by (uid=0)
Feb 11 16:45:01 haoka-2 sshd[3210540]: pam_systemd(sshd:session): Failed to create session: Start job for unit [email protected] failed with 'failed'
Feb 11 16:45:01 haoka-2 sshd[3210540]: pam_unix(sshd:session): session opened for user jumpuser01 by (uid=0)
Feb 11 16:45:01 haoka-2 sshd[3210540]: error: PAM: pam_open_session(): Permission denied

原因:limits.conf文件中的nofile值太大导致无法登录。
解决:按照如下步骤处理:
1、备份 /etc/sysctl.conf 文件并永久设置 fs.file-max及fs.nr_open 值
备份:

cp /etc/sysctl.conf /etc/sysctl.conf_bak

2、编辑 /etc/sysctl.conf  文件,在文件结尾添加如下信息:

fs.file-max = 2000000
fs.nr_open = 2000000

注意file-max 的值必须小于或等于nr_open值否则会出问题
    说明:

        fs.file-max:系统内核级别所有进程可打开的文件数。
        fs.nr_open:系统内核级别单个进程可打开的文件数。
3、执行命令  sysctl -p 即可看到修改后的值,如图。

4、编辑/etc/security/limits.conf 修改如下配置,本文将值修改为 65535,具体数值以实际环境为准
修改前备份一下文件

cp /etc/security/limits.conf /etc/security/limits.conf_bak

* soft nofile 65535
* hard nofile 65535

修改后如图

修改后重启下服务器即可登录。






 
301免备案跳转微信公众号
华为服务器
腾讯云服务器大促销。

声明:站长码字很辛苦啊,转载时请保留本声明及附带文章链接:https://www.zfcdn.xyz/showinfo-3-36190-0.html
亲爱的:被墙域名跳转TG:@qianhenetwork QQ:851617266,可否收藏+评论+分享呢?
上一篇:Docker容器执行su命令报错su: cannot open session: Permission denied 解决方法
下一篇:Linux系统Docker容器内部无法ping通域名以及无法访问外网处理方法