关于ssh登录时卡顿30s左右的问题调试处理

一、问题描述

内网ssh一台主机时,每次总是卡顿30s左右才能跳到远程主机上,其他主机ssh均正常,对比各主机配置并无特殊不同,那我们接下来分析下如何定位主机的可能原因

ssh采用对称你要加密,即使用公钥 (public key):提供给远程主机进行数据加密的行为,大家都能取得你的公钥来将数据加密的意思;私钥 (private key):远程主机使用你的公钥加密的数据,在本地端就能够使用私钥来进行解密。
在这里插入图片描述

二、分析处理

1)命令选项调试

-o GSSAPIAuthentication=no或-o strictHostKeyChecking=no选项进行ssh登录测试。

debug1: SSH2_MSG_SERVICE_ACCEPT received    //ssh卡顿出现在此处,从下可发现,在GSS认证过程中,尝试了多次,最好采用密钥对方式
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
Cannot determine realm for numeric host address

debug1: Unspecified GSS failure.  Minor code may provide more information
Cannot determine realm for numeric host address

debug1: Unspecified GSS failure.  Minor code may provide more information


debug1: Unspecified GSS failure.  Minor code may provide more information
Cannot determine realm for numeric host address

debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/identity
debug1: Offering public key: /root/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: read PEM private key done: type RSA

在这里插入图片描述
2)修改GSS认证

vim /etc/ssh/sshd_config   //注释如下2行,验证未果
#GSSAPIAuthentication yes
#GSSAPICleanupCredentials yes

3)重启后再次验证发现,仍出现卡顿,卡顿点如下:

debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received  //卡顿仍出现在此处

debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/identity
debug1: Offering public key: /root/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = zh_CN.UTF-8

对比正常登录的主机日志,并未发现异常;正常主机即时使用GSS认证也未出现卡顿,唯一区别就是卡顿主机使用别的ssh端口;对比/etc/pam.d/sshd 也是一样的,未发现异同;

4)关闭DNS解析,编辑/etc/ssh/sshd_config ,修改 UseDNS no,测试验证登录不再卡顿。即现场验证:ssh默认开启DNS解析的,即使未配置为yes;

5)经测试验证,开启GSS认证并不是导致本次ssh登录卡顿的原因,UseDNS选项是本次的主要直接原因;但是其他正常主机未开启也未运行ssh登录,受影响主机与其他正常主机不同的地方就是主机名修改了,不是默认的localhost了,但是ping测试依然显示正常。

注:UseDNS特性是SSH服务的安全增强特性,默认是打开的。开启后,服务端会先根据客户端IP进行DNS PTR反向查询,得到客户端主机名。再根据得到的客户端主机名进行DNS正向A记录查询,最后比对得到的IP与原始IP是否一致,用以防止客户端欺骗。尤其启用GSSAPI认证后,它需要借助于域名进行身份认证。

猜你喜欢

转载自blog.csdn.net/ximenjianxue/article/details/125661311
今日推荐