解决ssh连接慢的问题

-
-
2024-08-01

服务器地址配置好后可以Ping通,但ssh连接等待很久才可以认证

使用ssh -v选项显示debug信息

[root@DESKTOP-27TTR5P ~]# ssh [email protected] -v
OpenSSH_9.8p1, OpenSSL 3.3.1 4 Jun 2024
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Reading configuration data /etc/ssh/ssh_config.d/20-systemd-ssh-pro
xy.conf
debug1: Connecting to 10.0.0.10 [10.0.0.10] port 22.
debug1: Connection established.
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa_sk type -1
debug1: identity file /root/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: identity file /root/.ssh/id_ed25519_sk type -1
debug1: identity file /root/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /root/.ssh/id_xmss type -1
debug1: identity file /root/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_9.8
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: compat_banner: match: OpenSSH_7.4 pat OpenSSH_7.4* compat 0x0400000
6
debug1: Authenticating to 10.0.0.10:22 as 'root'
debug1: load_hostkeys: fopen /root/.ssh/known_hosts2: No such file or direc
tory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or dire
ctory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or dir
ectory
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: [email protected] MAC: <imp
licit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <imp
licit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:FOto4EN8oODetS8ohgGlDdfkhQSUjgV
mALsOt+8GiT0
debug1: load_hostkeys: fopen /root/.ssh/known_hosts2: No such file or direc
tory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or dire
ctory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or dir
ectory
debug1: Host '10.0.0.10' is known and matches the ED25519 host key.        
debug1: Found key in /root/.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: SSH2_MSG_EXT_INFO received
debug1: kex_ext_info_client_parse: server-sig-algs=<rsa-sha2-256,rsa-sha2-5
12>
debug1: SSH2_MSG_SERVICE_ACCEPT received
# ==========================
# 卡在这里很久
# ==========================
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Will attempt key: /root/.ssh/id_rsa
debug1: Will attempt key: /root/.ssh/id_ecdsa
debug1: Will attempt key: /root/.ssh/id_ecdsa_sk
debug1: Will attempt key: /root/.ssh/id_ed25519
debug1: Will attempt key: /root/.ssh/id_ed25519_sk
debug1: Will attempt key: /root/.ssh/id_xmss
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Trying private key: /root/.ssh/id_ecdsa_sk
debug1: Trying private key: /root/.ssh/id_ed25519
debug1: Trying private key: /root/.ssh/id_ed25519_sk
debug1: Trying private key: /root/.ssh/id_xmss
debug1: Next authentication method: password
[email protected]'s password:
Authenticated to 10.0.0.10 ([10.0.0.10]:22) using "password".
debug1: channel 0: new session [client-session] (inactive timeout: 0)      
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: filesystem
debug1: client_input_global_request: rtype [email protected] want_rep
ly 0
debug1: client_input_hostkeys: searching /root/.ssh/known_hosts for 10.0.0.
10 / (none)
debug1: client_input_hostkeys: searching /root/.ssh/known_hosts2 for 10.0.0
.10 / (none)
debug1: client_input_hostkeys: hostkeys file /root/.ssh/known_hosts2 does n
ot exist
debug1: client_global_hostkeys_prove_confirm: server used untrusted RSA sig
nature algorithm ssh-rsa for key 0, disregarding
debug1: update_known_hosts: known hosts file /root/.ssh/known_hosts2 does n
ot exist
debug1: pledge: fork
Last login: Wed Jul 24 12:50:15 2024 from 10.0.0.1

查看哪里卡住了

debug1: SSH2_MSG_SERVICE_ACCEPT received # 卡在这一行

这里可能是使用DNS解析超时导致的,可以在sshd_config中禁用DNS

# /etc/ssh/sshd_config
UseDNS no

ssh可能在解析主机名、反向解析、证书验证、DNSSEC等情况下使用DNS解析,如果DNS配置错误、内网无DNS服务等情况导致ssh等待DNS解析。

重启sshd服务

sudo systemctl restart sshd

 

“您的支持是我持续分享的动力”

微信收款码
微信
支付宝收款码
支付宝

采唐
采唐的狐言狐语🦊
公告

欢迎欢迎!这是采唐的新博客页!
最新评论

加载中...