博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
rh436 - ssh验证/连接很慢
阅读量:4177 次
发布时间:2019-05-26

本文共 3942 字,大约阅读时间需要 13 分钟。

版本:

客户端(client):

[root@desktop20 ~]# cat /proc/version

Linux version 2.6.32-220.el6.x86_64 (mockbuild@x86-004.build.bos.redhat.com) (gcc version 4.4.5 20110214 (Red Hat 4.4.5-6) (GCC) ) #1 SMP Wed Nov 9 08:03:13 EST 2011
[root@desktop20 ~]#

服务端(server):

[root@node1 ~]# cat /proc/version

Linux version 2.6.32-220.el6.x86_64 (mockbuild@x86-004.build.bos.redhat.com) (gcc version 4.4.5 20110214 (Red Hat 4.4.5-6) (GCC) ) #1 SMP Wed Nov 9 08:03:13 EST 2011
[root@node1 ~]#

症状:

在客户端执行ssh node1时,要等大概10秒才能出现输入密码的提示

解决:

================================================

使用strace跟踪,发现有个select函数用了10秒钟,查了半天也不知道到底是什么引起的(汗!-_- ...)

strace -o ssh.trc -fTttt ssh node4

view ssh.trc

... ...

    520 38328 1367794302.169155 connect(4, {sa_family=AF_FILE, path="/tmp/keyring-24Tr0l/socket.ssh"        }, 110) = 0 <0.000579>

    521 38328 1367794302.169947 write(4, "\0\0\0\1", 4) = 4 <0.000040>
    522 38328 1367794302.170091 write(4, "\v", 1) = 1 <0.000030>
    523 38328 1367794302.170213 read(4, "\0\0\1<", 4) = 4 <0.001052>
    524 38328 1367794302.171505 read(4, "\f\0\0\0\1\0\0\1\25\0\0\0\7ssh-rsa\0\0\0\1#\0\0\1\1\0\237n"        ..., 316) = 316 <0.000041>
    525 38328 1367794302.171831 write(3, "\177j\340\2263\3\245\26\360\231 \v\335]\364\353\276`t\256b        .\3\204rc\360\364'yKT"..., 64) = 64 <0.000207>
    526 38328 1367794302.172189 select(4, [3], NULL, NULL, NULL) = 1 (in [3]) <10.022289>
    527 38328 1367794312.194794 read(3, "s\374\275q\361\\\333\306\30g\2K\216\362@\267LG~k\343\312\23        2\223lJ\206\32s\330%H"..., 8192) = 80 <0.000014>
    528 38328 1367794312.194905 write(3, "=\310\33\227X\3142=R&*\302a\320\0R\202\334\372)\215\24\264        \20\256\tZ\20\332\263\357\245"..., 368) = 368 <0.000075>
    529 38328 1367794312.195019 select(4, [3], NULL, NULL, NULL) = 1 (in [3]) <0.007280>
    530 38328 1367794312.202396 read(3, "\261\200\311L\240\342\332\213:J\246\t\7Ctk\224\16\362\370\2        7\275\33^f\327D\3504\337\323\344"..., 8192) = 320 <0.000026>
    531 38328 1367794312.202557 write(4, "\0\0\2\223", 4) = 4 <0.000038>
... ...

526: vim里的行号

38328:进程ID

1367794302.172189:自1970-01-01 00:00:00 UTC到现在的秒数,精确到小数点后六位

select(4, [3], NULL, NULL, NULL) :select函数和参数

= 1:select函数的返回值

(in [3]) :?

<10.022289> :select函数用了多少秒,,精确到小数点后六位

================================================

strace搞不定,试试开启ssh的debug信息,看看能查到什么

ssh -vvv node1

... ...

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

Credentials cache file '/tmp/krb5cc_0' not found
debug1: Unspecified GSS failure.  Minor code may provide more information
... ...

看来是客户端启用了kerbose验证,但是我没打算使用kerbose验证,于是关了这个选项。

[root@desktop20 ssh]# grep GSSAPIAuthentication /etc/ssh/ssh_config

    GSSAPIAuthentication no
[root@desktop20 ssh]# 

关了之后,之前的提示没有了,可是问题依旧,ssh node1还是要等10秒。

(事实上GSS验证超时确实是发起ssh连接后要等很长时间才能输入密码的一个原因,但在这篇文章里只是原因之一,所以这里关闭客户端的GSS验证效果并不明显)

再执行ssh -vvv node1时发现总会在“debug3: Wrote 64 bytes for a total of 1109”卡上一小段时间

... ...

debug1: SSH2_MSG_NEWKEYS received

debug1: SSH2_MSG_SERVICE_REQUEST sent
debug3: Wrote 48 bytes for a total of 1045
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /root/.ssh/identity ((nil))
debug2: key: /root/.ssh/id_rsa (0x7f1391a6d970)
debug2: key: /root/.ssh/id_dsa ((nil))
debug3: Wrote 64 bytes for a total of 1109
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug3: start over, passed a different list publickey,gssapi-keyex,gssapi-with-mic,password
debug3: preferred publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password

... ...

================================================

GOOGLE一圈之后发现不少回答都提到了服务端打开的UseDNS选项可能是问题的原因,于是关闭服务端UseDNS选项,重启sshd服务

[root@node1 ~]# grep UseDNS /etc/ssh/sshd_config

UseDNS no
[root@node1 ~]# /etc/init.d/sshd restart
Stopping sshd:                                             [  OK  ]
Starting sshd:                                             [  OK  ]
[root@node1 ~]#
果然,现在从客户端ssh node1几乎是秒连。

REF:

1. ssh 连接很慢的解决办法

2. Slow SSH authentication times

http://ubuntuforums.org/showthread.php?t=1605241

转载地址:http://litai.baihongyu.com/

你可能感兴趣的文章
将xml中的数据导入到数据库
查看>>
Qt容器测试
查看>>
自定义插件
查看>>
编译数据库ODBC
查看>>
无法解析的外部符号的 3 种可能
查看>>
webalizer流量分析软件windows下的配置与使用
查看>>
Java的数组(Array)、Vector、ArrayList、HashMap的异同
查看>>
Apache的使用方法
查看>>
PHP环境配置:Apach+Tomcat+mysql+php
查看>>
CVE-2019-0708漏洞影响面分析及采用多种规则的检测方法
查看>>
拿走不谢!固件逆向分析过程中的工具和技巧(上)
查看>>
整理网络安全措施的5个小技巧
查看>>
入侵win10(下)--渗透系统
查看>>
烦请解释一下“驱动表”的概念
查看>>
IPAide(IP助手) v1.01
查看>>
Oracle 11g RAC SCAN basics
查看>>
ASM appears to be running, but connect via sqlplus, says idle instance.??
查看>>
Oracle EBS R12 - Steps and Issues/Resolutions during R12.1.1 to R12.1.3 Upgration
查看>>
跳过17:30,跳过瑞星定时扫描
查看>>
自动订饭
查看>>