linux升级openssh后打开打开文件数ulimit重置为1024问题解决

本文详细介绍了如何解决服务器SSH存在的漏洞,包括升级OpenSSH、修复免秘钥登录失效问题、调整文件描述符限制,以及具体的配置修改步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.现象

        通过绿盟等安扫软件扫描到服务器ssh存在漏洞,需要升级修复,升级openssh后,出现的问题:

  • 问题1:多个服务器之间免秘钥登陆失效
  • 问题2:单个服务器通过ulimit -a查看到的打开文件数被重置为1024,过小

2.解决方法

#1.安装pam-devel
yum install -y pam-devel

#2.下载最新版本openssh并解包、编译安装
#下载
cd /temp
wget http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.0p1.tar.gz
#解压
tar zxf openssh-8.0p1.tar.gz
#配置
./configure --prefix=/usr/ --sysconfdir=/etc/ssh --with-pam
#编译安装
make && make install
#覆盖老的安装,加入开机启动
cp /tmp/openssh-8.0p1/contrib/redhat/sshd.init /etc/init.d/sshd
chkconfig sshd --add

#3.修改/etc/ssh/sshd_config
vi /etc/ssh/sshd_config
添加UsePAM yes     
修改PermitRootLogin yes

#4.修改/etc/security/limits.conf
编辑vi /etc/security/limits.conf
* soft nofile 40960
* hard nofile 81920

#5.修改/etc/pam.d/sshd
编辑vi /etc/pam.d/sshd
#%PAM-1.0
auth       include      system-auth
account    required     pam_nologin.so
account    include      system-auth
password   include      system-auth
session    optional     pam_keyinit.so force revoke
session    include      system-auth
session    required     pam_loginuid.so
session    required     pam_limits.so

 

查看错误原因,[13:54:37.578] Log Level: 2 [13:54:37.580] remote-ssh@0.76.1 [13:54:37.580] win32 x64 [13:54:37.586] SSH Resolver called for "ssh-remote+112.74.167.19:22", attempt 1 [13:54:37.586] "remote.SSH.useLocalServer": false [13:54:37.586] "remote.SSH.showLoginTerminal": false [13:54:37.587] "remote.SSH.remotePlatform": {"112.74.167.19":"linux"} [13:54:37.587] "remote.SSH.path": undefined [13:54:37.587] "remote.SSH.configFile": undefined [13:54:37.587] "remote.SSH.useFlock": true [13:54:37.587] "remote.SSH.lockfilesInTmp": false [13:54:37.587] "remote.SSH.localServerDownload": auto [13:54:37.587] "remote.SSH.remoteServerListenOnSocket": false [13:54:37.587] "remote.SSH.showLoginTerminal": false [13:54:37.587] "remote.SSH.defaultExtensions": [] [13:54:37.587] "remote.SSH.loglevel": 2 [13:54:37.587] "remote.SSH.enableDynamicForwarding": true [13:54:37.588] "remote.SSH.enableRemoteCommand": false [13:54:37.589] "remote.SSH.serverPickPortsFromRange": {} [13:54:37.589] "remote.SSH.serverInstallPath": {} [13:54:37.623] SSH Resolver called for host: 112.74.167.19 [13:54:37.623] Setting up SSH remote "112.74.167.19" [13:54:37.628] Using commit id "b3e4e68a0bc097f0ae7907b217c1119af9e03435" and quality "stable" for server [13:54:37.630] Install and start server if needed [13:54:37.632] Checking ssh with "ssh -V" [13:54:37.681] > OpenSSH_for_Windows_9.5p1, LibreSSL 3.8.2 [13:54:37.686] Running script with connection command: ssh -T -D 65236 -p 22 "112.74.167.19" bash [13:54:37.688] Terminal shell path: C:\WINDOWS\System32\cmd.exe [13:54:37.873] > [?9001h[?1004h [13:54:37.873] Got some output, clearing connection timeout [13:54:38.185] > forest@112.74.167.19's password:]0;C:\WINDOWS\System32\cmd.exe [13:54:38.185] Showing password prompt [13:54:42.934] Got password response [13:54:42.934] "install" wrote data to terminal: "*********" [13:54:42.946] > [13:54:44.974] > Permission denied, please try again. [13:54:44.982] > forest@112.74.167.19's password: [13:54:44.982] Showing password prompt [13:54:51.552] Got password response [13:54:51.553] "install" wrote data to terminal: "*********" [13:54:51.564] > [13:54:54.023] > Permission denied, please try again. [13:54:54.044] > forest@112.74.167.19's password: [13:54:54.044] Showing password prompt [13:54:57.559] Got password response [13:54:57.559] "install" wrote data to terminal: "*********" [13:54:57.569] > [13:54:59.182] > forest@112.74.167.19: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password). [13:54:59.197] > 过程试图写入的管道不存在。 [13:55:00.565] "install" terminal command done [13:55:00.566] Install terminal quit with output: 过程试图写入的管道不存在。 [13:55:00.566] Received install output: 过程试图写入的管道不存在。 [13:55:00.566] Failed to parse remote port from server output [13:55:00.567] Resolver error: Error: at f.Create (c:\Users\forest\.vscode\extensions\ms-vscode-remote.remote-ssh-0.76.1\out\extension.js:1:586041) at t.handleInstallOutput (c:\Users\forest\.vscode\extensions\ms-vscode-remote.remote-ssh-0.76.1\out\extension.js:1:584693) at t.tryInstall (c:\Users\forest\.vscode\extensions\ms-vscode-remote.remote-ssh-0.76.1\out\extension.js:1:681846) at async c:\Users\forest\.vscode\extensions\ms-vscode-remote.remote-ssh-0.76.1\out\extension.js:1:644486 at async t.withShowDetailsEvent (c:\Users\forest\.vscode\extensions\ms-vscode-remote.remote-ssh-0.76.1\out\extension.js:1:647831) at async t.resolve (c:\Users\forest\.vscode\extensions\ms-vscode-remote.remote-ssh-0.76.1\out\extension.js:1:645565) at async c:\Users\forest\.vscode\extensions\ms-vscode-remote.remote-ssh-0.76.1\out\extension.js:1:722872 [13:55:00.571] ------
最新发布
08-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值