ssh远程登录Linux卡慢的全过程排查及解决方案

前言:

  在linux操作系统使用过程中偶然一次感到使用ssh远程连接软件连接操作系统需要等待许久,第一次没在意,第二次也没在意,第三次有点忍受不住了,就抽时间想解决掉这个问题,顺便写下这篇博文已帮助更多的人解决次烦恼。

  ssh慢普遍原因是因为DNS解析导致,如果还不行那就查看ssh远程登录的全过程。那么,实战正式开始~

测试环境:

 CentOS 6.7 2.6.-.el6.x86_64

更改ssh配置文件设置禁用DNS解析:

1、在ssh服务端上更改/etc/ssh/sshd_config文件中的配置为如下内容:

 UseDNS no

然后,保存并退出,执行/etc/init.d/sshd restart重启sshd进程使上述配置生效,在连接应该就不慢了。如果再慢就要使用如下排除过程。

排查过程:

  首先用到的命令就是:ssh -v 相信大家对此并不陌生,工欲善其事必先利其器,现在有了,那就可以开始浪了~

 [root@ ~]# ssh -v root@192.168.222.129
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips Feb
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 192.168.222.129 [192.168.222.129] port .
debug1: Connection established.
debug1: permanently_set_uid: /
debug1: identity file /root/.ssh/identity type -
debug1: identity file /root/.ssh/identity-cert type -
debug1: identity file /root/.ssh/id_rsa type -
debug1: identity file /root/.ssh/id_rsa-cert type -
debug1: identity file /root/.ssh/id_dsa type -
debug1: identity file /root/.ssh/id_dsa-cert type -
debug1: identity file /root/.ssh/id_ecdsa type -
debug1: identity file /root/.ssh/id_ecdsa-cert type -
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.
debug1: match: OpenSSH_5. pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(<<) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
The authenticity of host '192.168.222.129 (192.168.222.129)' can't be established.
RSA key fingerprint is :bf:ab:::::d4:::ab:a7:::d3:f9.
Are you sure you want to continue connecting (yes/no)? y #此处手残,顺手打了个“y” 正确的在下面 - -、
Please type 'yes' or 'no': yes 我是正确的 ☺
Warning: Permanently added '192.168.222.129' (RSA) to the list of known hosts.
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received 那么重点来了。当执行到此环节的是出现了卡顿的现象,博主机智的敲了几下回车与其隔开方便后来查看~

     好吧言归正传...

 debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password  #此处提示认证可以继续。but......下面似乎没有那么顺利
debug1: Next authentication method: gssapi-keyex         #下一步验证方法:GSSAPI-keyex~
debug1: No valid Key exchange context                #好吧,似乎也死掉了。。提示木有有效的密钥交换环境,也就是说
debug1: Next authentication method: gssapi-with-mic #可以看出此处系统不死心。。又使用下一个验证方法:gssapi-with-mic,但是以失败告终,那么我们再往后看。

 reverse mapping checking getaddrinfo for bogon [192.168.222.129] failed - POSSIBLE BREAK-IN ATTEMPT!
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
Credentials cache file '/tmp/krb5cc_0' not found debug1: Unspecified GSS failure. Minor code may provide more information debug1: Unspecified GSS failure. Minor code may provide more information
Credentials cache file '/tmp/krb5cc_0' not found debug1: Next authentication method: publickey                #经过几次挫折,系统放弃了..启用了publickey验证方式
debug1: Trying private key: /root/.ssh/identity
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Next authentication method: password
root@192.168.222.129's password:

  从上面反馈的结果中我们发现,是GSSAPI验证在捣鬼,那我们将其禁用不就好了。。

解决方法:

首先编辑ssh配置文件:

  vim /etc/ssh/sshd_config

 # GSSAPI options
#GSSAPIAuthentication no
GSSAPIAuthentication yes        #←这一行大约在文档的第81行,我们看到它开启了yes的状态,而GSSAPIAuthentication no被无情的注释掉了。。。我们可以将其放出来,,或者将yes改成no
 #GSSAPICleanupCredentials yes 
GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

然后保存退出:wq 重启一下ssh服务即可。

ok这样基本就解决了所有问题~

【浅层优化实战】ssh远程登录Linux卡慢的全过程排查及解决方案的更多相关文章

  1. ssh远程登录linux服务器

    ssh远程登录linux服务器 用法: ssh -l user -p port server_ip 或者 ssh -p port user@server_ip 参数: -l 后接要登录的远程系统用户名 ...

  2. SSH客户端(如PuTTY)ssh远程登录Linux非常慢的解决方法

    转:http://blog.useasp.net/archive/2014/05/19/solved-the-problem-of-ssh-client-such-as-putty-remote-lo ...

  3. ssh远程登录linux live系统

    要想ssh远程登录,须要准备两件事:配置同网段IP和开启SSH服务. 因为live系统没有IP,所以首先须要配置IP. 我的live系统是在虚拟机上启动的,宿主IP为192.168.230.1,liv ...

  4. Windows通过SSH远程登录Linux主机

    准备工作:1.Windows系统下装有VMware虚拟机且是Linux系统2.终端连接工具Xshell 63.本次实验系统IP如下 系统 IP Windows10 192.168.37.111 Cen ...

  5. windows下如何使用ssh远程登录Linux

    1.ssh的安装 sudo apt-get install ssh 或者在Linux情况下,自带有ssh,从第二步开始   2.生成密钥 ssh-keygen 中间过程会提示你存放密钥的地方Enter ...

  6. SSH免密码远程登录Linux

    1. 有A,B两台机(Linux/unix), 要想从A用ssh远程登录到B上(假设各自的IP,A:192.168.100:B:192.168.1.104). 2. 在A机上,用“ssh-keygen ...

  7. Linux实现利用SSH远程登录服务器详解

    Linux实现利用SSH远程登录服务器详解 http://www.111cn.net/sys/linux/55152.htm

  8. Linux—修改ssh远程登录信息

    修改ssh远程登录端口 1.修改ssh服务的配置文件:/etc/ssh/sshd_config ,将 Port 22 改为 Port 3120 保存退出. [root@localhost ~]# vi ...

  9. 使用SSH客户端远程登录Linux主机

    使用SSH客户端远程登录Linux主机(可替代samba.ftp服务) . Linux系统起初就是为多用户而产生的,可以允许多个用户同时登录linux主机各自进行操作,如图1所示: 图1 SSH(Se ...

随机推荐

  1. awk中分隔符转换

    awk中分隔符转换的问题(转) 在awk中明明用OFS重新设置了分隔符,为什么在输出的时候还是原样输出呢! 他是这么写的:    echo 1,2,3,4 | awk 'BEGIN{FS=" ...

  2. 用pecl/pear独立编译PHP扩展 vs. 把扩展编译到PHP内核中

    将扩展编译到php内部的方式会提高php运行扩展的效率,但是每次需要新添加扩展时都需要把php以及之前添加的所有扩展重新编译一边,非常麻烦. 独立编译扩展,php外部调用扩展的方式虽然会牺牲一点点的性 ...

  3. Android sdk目录介绍

    android sdk目录介绍 build-tools 各版本SDK编译工具 docs 离线开发者文档Android SDK API参考文档 extras 扩展开发包,如兼容架包. platforms ...

  4. php : DOM 操作 XML

    DOM 操作 XML 基本用法 XML文件: person.XML <?xml version="1.0" encoding="utf-8" ?> ...

  5. php : 基础(2)

    常量 常量是相对于变量来说的:是一个其中存储的数据不会也不应该改变的"标识符". 常量的使用,就2个方面:定义,取值. 常量的定义 //常量定义语法1: //define(&quo ...

  6. G将军的敢死队——树状DP

    当前节点的两种情况: 1.beChoosed = {son.beAbandoned乘积} //当前节点选中的情况下,子节点都不能选 2.beAbandoned = {(son.beAbandoned ...

  7. CSS 文字两端对齐

    <!DOCTYPE HTML> <html> <head> <title></title> <meta http-equiv=&quo ...

  8. 01.JavaScript 面向对象精要--原始类型和引用类型

    一.什么是类型 JavaScript 虽然没有类的概念.但依然存在两种类型:原始类型和应用类型. 原始类型保存为简单的数据值,引用类型则保存为对象,其本质是指向内存位置 的引用.也就是说:原始值被直接 ...

  9. (转)Sqoop中文手册

    Sqoop中文手册 1.     概述 本文档主要对SQOOP的使用进行了说明,参考内容主要来自于Cloudera SQOOP的官方文档.为了用中文更清楚明白地描述各参数的使用含义,本文档几乎所有参数 ...

  10. 个人评测——K米

    K米APP案例分析 关于 K米 -- 的案例分析 产品 K米的APP (全国KTV点歌,手机直播,互动,交友,预订)的Android客户端 第一部分 调研,评测 评测: 软件的bug,功能评测,黑箱测 ...