标题:[实践OK]Linux出现Too many open files in system强制重启,原因是恶意用户连接SSH导致ssh-agent进程太多,最后只有reset键和长按关机键关机。 出处:向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除 时间:Wed, 16 May 2018 22:51:12 +0000 作者:jackxiang 地址:http://jackxiang.com/post/9751/ 内容: 原因:外网试图登录SSH破解密码太多,出现大量的/usr/bin/ssh-agent -s进程。ssh-agent会随着当前ssh会话的消失而消失,这也是一种安全机制. 解决办法如下: cat /etc/profile.d/ssh-agent.sh #!/bin/sh if [ -f ~/.agent.env ]; then . ~/.agent.env >/dev/null if ! kill -0 $SSH_AGENT_PID >/dev/null 2>&1; then echo "Stale agent file found. Spawning new agent..." eval `ssh-agent |tee ~/.agent.env` ssh-add fi else echo "Starting ssh-agent..." eval `ssh-agent |tee ~/.agent.env` ssh-add fi 运行: [root@localhost ~]# sh /etc/profile.d/ssh-agent.sh Starting ssh-agent... Agent pid 3625 [root@localhost ~]# ps -ef|grep 3625 root 3625 1 0 22:57 ? 00:00:00 ssh-agent root 3647 3325 0 22:57 pts/2 00:00:00 grep --color=auto 3625 后面再多个SSH,只有四个ssh-agent进程: ps -ef|grep ssh-agent root 3625 1 0 22:57 ? 00:00:00 ssh-agent root 2442 1 0 22:54 ? 00:00:00 /usr/bin/ssh-agent -s root 2785 1 0 22:55 ? 00:00:00 /usr/bin/ssh-agent -s root 3131 1 0 22:56 ? 00:00:00 /usr/bin/ssh-agent -s root 3527 1 0 22:57 ? 00:00:00 /usr/bin/ssh-agent -s root 3878 1 0 22:58 ? 00:00:00 /usr/bin/ssh-agent -s cat ~/.agent.env SSH_AUTH_SOCK=/tmp/ssh-X1RtYLOVI2iq/agent.3623; export SSH_AUTH_SOCK; SSH_AGENT_PID=3625; export SSH_AGENT_PID; echo Agent pid 3625; 感觉进程数还是变多,无鸟用,于是干掉这个SSH-Client: [root@localhost ~]# rpm -qf /usr/bin/ssh-agent openssh-clients-7.4p1-13.el7_4.x86_64 [root@localhost ~]# rpm -e openssh-clients 错误:依赖检测失败: openssh-clients 被 (已安裝) virt-viewer-5.0-7.el7.x86_64 需要 openssh-clients 被 (已安裝) python-meh-0.25.2-1.el7.noarch 需要 [root@localhost ~]# yum remove openssh-clients -y 作为依赖被删除: anaconda-core.x86_64 0:21.48.22.121-1.el7.centos anaconda-gui.x86_64 0:21.48.22.121-1.el7.centos anaconda-tui.x86_64 0:21.48.22.121-1.el7.centos initial-setup.x86_64 0:0.3.9.40-1.el7.centos initial-setup-gui.x86_64 0:0.3.9.40-1.el7.centos python-meh.noarch 0:0.25.2-1.el7 python-meh-gui.noarch 0:0.25.2-1.el7 virt-viewer.x86_64 0:5.0-7.el7 参考自:https://blog.csdn.net/diamondxiao/article/details/52488628 一)SSH现象: ps -ef|grep ssh-agent|wc -l -bash: 管道错误: Too many open files in system -bash: start_pipeline: 进程组管道: Too many open files in system lsof -n |awk '{print $2}'|sort|uniq -c |sort -nr|more -bash: /usr/bin/sort: Too many open files in system -bash: /usr/bin/sort: Too many open files in system lsof: error while loading shared libraries: libdl.so.2: cannot open shared object file: Error 23 rpm -qa|grep ssh-agent error: Failed to initialize NSS library [xiangdong@localhost ~]$ yum update nspr There was a problem importing one of the Python modules required to run yum. The error leading to this problem was: libz.so.1: cannot open shared object file: Too many open files in system reboot /usr/bin/pkttyagent: error while loading shared libraries: libffi.so.6: cannot open shared object file: Error 23 Failed to execute operation: 连接超时 sudo su - 上一次登录:一 5月 14 23:12:47 CST 2018:0 上 最后一次失败的登录:三 5月 16 22:27:19 CST 2018从 218.65.30.53ssh:notty 上 最有一次成功登录后有 64523 次失败的登录尝试。 [root@localhost ~]# reboot uptime -bash: start_pipeline: 进程组管道: Too many open files in system -bash: /usr/bin/uptime: Too many open files in system id -bash: start_pipeline: 进程组管道: Too many open files in system -bash: /usr/bin/id: Too many open files in system ps -ef|grep ssh -bash: 管道错误: Too many open files in system -bash: start_pipeline: 进程组管道: Too many open files in system 二)Linux桌面没了,出现: 系统出现kernel: audit: backlog limit exceeded提示 error: audit:backlog limit exceeded报错,audit缓冲大小瓶颈 来自:http://blog.51cto.com/jschu/1769025 三)如何强制重启? 有时候,linux 由于硬盘或者其它原因, 某个进程挂住了,怎么也杀不死, 输入 reboot 命令也无法重启。 这时候,一般只能按机箱上的reset健来重启了。 如果是远程ssh,那怎么办呢? 下面两行命令可以搞定: echo 1 > /proc/sys/kernel/sysrq echo b > /proc/sysrq-trigger ========================================================= Linux使用shutdown -r now 或者 reboot、init 6 命令无法重启时使用以下两条命令可强制重启: echo 1 > /proc/sys/kernel/sysrq echo b > /proc/sysrq-trigger 1./proc/sys/kernel/sysrq 向 sysrq 文件中写入1是为了开启 SysRq 功能。根据 linux/Documentations/sysrq.txt 中所说:SysRq 代表的是 Magic System Request Key。开启了这个功能以后,只要内核没有挂掉,它就会响应你要求的任何操作。但是这需要内核支持(CONFIG_MAGIC_SYSRQ 选项)。向 /proc/sys/kernel/sysrq 中写入0是关闭 SysRq 功能,写入1是开启,其他选项请参考 sysrq.txt。 2./proc/sysrq-trigger 立即重新启动计算机: echo "b" > /proc/sysrq-trigger 立即关闭计算机: echo "o" > /proc/sysrq-trigger 来自:https://my.oschina.net/dongsong/blog/915358 Generated by Jackxiang's Bo-blog 2.1.1 Release