问问这个问题怎么解决啊,上午还好好的,中午吃完饭回来突然发现服务器登不上去了,在终端里输入ssh lab报错的是:
> user@.. ~ % ssh lab
kex_exchange_identification: Connection closed by remote host
Connection closed by xxx.xx.x.xxx port 22
再输入ssh -v lab@xxx.xxx.xxx.xxx 更详细的报错如下:
> user@... ~ % ssh -v lab@xxx.xxx.xxx.xxx
OpenSSH_9.0p1, LibreSSL 3.3.6
debug1: Reading configuration data /Users/.../.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
debug1: /etc/ssh/ssh_config line 54: Applying options for *
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: Connecting to xxx.xxx.xxx.xxx [xxx.xxx.xxx.xxx] port 22.
debug1: Connection established.
debug1: identity file /Users/.../.ssh/id_rsa type 0
debug1: identity file /Users/.../.ssh/id_rsa-cert type -1
debug1: identity file /Users/.../.ssh/id_ecdsa type -1
debug1: identity file /Users/.../.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/.../.ssh/id_ecdsa_sk type -1
debug1: identity file /Users/.../.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /Users/.../.ssh/id_ed25519 type -1
debug1: identity file /Users/..../ssh/id_ed25519-cert type -1
debug1: identity file /Users/.../.ssh/id_ed25519_sk type -1
debug1: identity file /Users/.../.ssh/id_ed25519_sk-cert type -1
debug1: identity file /Users/.../.ssh/id_xmss type -1
debug1: identity file /Users/.../.ssh/id_xmss-cert type -1
debug1: identity file /Users/.../.ssh/id_dsa type -1
debug1: identity file /Users/.../.ssh/id_dsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_9.0
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.0
debug1: compat_banner: match: OpenSSH_8.0 pat OpenSSH* compat 0x04000000
debug1: Authenticating to xxx.xxx.xxx.xx:22 as 'lab'
debug1: load_hostkeys: fopen /Users/.../.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ...
debug1: load_hostkeys: fopen /Users/.../.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host 'xxx.xxx.xxx.xxx' is known and matches the ED25519 host key.
debug1: Found key in /Users/zkey/.ssh/known_hosts:1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: get_agent_identities: bound agent to hostkey
debug1: get_agent_identities: ssh_fetch_identitylist: agent contains no identities
debug1: Will attempt key: /Users/.../.ssh/id_rsa ...
debug1: Will attempt key: /Users/.../.ssh/id_ecdsa
debug1: Will attempt key: /Users/.../.ssh/id_ecdsa_sk
debug1: Will attempt key: /Users/.../.ssh/id_ed25519
debug1: Will attempt key: /Users/.../.ssh/id_ed25519_sk
debug1: Will attempt key: /Users/.../.ssh/id_xmss
debug1: Will attempt key: /Users/.../.ssh/id_dsa
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: ...
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic
debug1: Next authentication method: publickey
debug1: Offering public key: /Users/.../.ssh/id_rsa RSA ...
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic
debug1: Trying private key: /Users/.../.ssh/id_ecdsa
debug1: Trying private key: /Users/.../.ssh/id_ecdsa_sk
debug1: Trying private key: /Users/.../.ssh/id_ed25519
debug1: Trying private key: /Users/.../.ssh/id_ed25519_sk
debug1: Trying private key: /Users/.../.ssh/id_xmss
debug1: Trying private key: /Users/.../.ssh/id_dsa
debug1: No more authentication methods to try.
lab@xxx.xxx.xxx.xxx: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
问问这个怎么解决!感谢!不然我的工作完不成了Orz
SSH连接数过多导致的
修改服务器上的文件:/etc/ssh/sshd_config,找到MaxSessions这一行,把这个改大点然后重启
或者重启下电脑
你把报错复制出来发过来
"Connection closed by remote host" 错误通常表示 SSH 连接被远程主机关闭,可能是由于多种原因引起的。以下是一些可能的解决方法:
网络连接问题: 检查你的网络连接是否稳定,确保你的本地网络和远程主机的网络都正常。如果你使用的是无线网络,可能会有信号不稳定的问题。
SSH 服务问题: 检查远程主机的 SSH 服务是否正常运行。确保 SSH 服务已经启动并监听正确的端口。你可以尝试在远程主机上重启 SSH 服务。
主机密钥问题: 如果你的 SSH 配置中使用了密钥进行认证,可能是因为远程主机的公钥或私钥不匹配导致连接被关闭。你可以尝试重新生成密钥对,并将公钥添加到远程主机的 ~/.ssh/authorized_keys 文件中。
防火墙或安全组设置: 检查你的本地防火墙、远程主机的防火墙以及任何网络安全组的设置,确保 SSH 的端口是开放的。
SSH 配置问题: 检查你的 SSH 配置文件(通常是 ~/.ssh/config),确保没有不正确的配置或参数。尤其要注意检查远程主机的配置。
连接超时: 如果你的连接在一段时间内没有活动,可能会因为连接超时而被关闭。你可以尝试在 SSH 命令中添加 -o ServerAliveInterval=60 参数来保持连接活跃。
远程主机负载高: 如果远程主机负载很高,可能会导致 SSH 连接被关闭。你可以尝试等一段时间后再次连接。
SSH 客户端版本不兼容: 确保你的 SSH 客户端版本与远程主机兼容。有时不同版本之间可能会有兼容性问题。
如果以上方法都无法解决问题,建议查看 SSH 日志文件以获取更详细的错误信息,这可以帮助你更准确地定位问题的原因。SSH 日志文件通常位于 /var/log/auth.log(对于 Linux)或 Event Viewer(对于 Windows)。如果问题仍然无法解决,你可能需要联系远程主机的管理员或技术支持以获取帮助。