ssh 登录很慢该如何解决

ssh登录很慢解决方法

使用ssh客户端(如:putty)连接Linux服务器,可能会等待10-30秒才有提示输入密码。严重影响工作效率。登录很慢,登录上去后速度正常,这种情况主要有两种可能的原因:

1. DNS反向解析问题

OpenSSH在用户登录的时候会验证IP,它根据用户的IP使用反向DNS找到主机名,再使用DNS找到IP地址,最后匹配一下登录的IP是否合法。如果客户机的IP没有域名,或者DNS服务器很慢或不通,那么登录就会很花时间。

解决办法:在目标服务器上修改sshd服务器端配置,并重启sshd

vi /etc/ssh/sshd_config
UseDNS no

2. 关闭ssh的gssapi认证

用ssh -v user@server 可以看到登录时有如下信息:

debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure. Minor code may provide more information

注:ssh -vvv user@server 可以看到更细的debug信息

解决办法:

修改sshd服务器端配置

vi /etc/ssh/ssh_config
GSSAPIAuthentication no

可以使用ssh -o GSSAPIAuthentication=no user@server登录

GSSAPI ( Generic Security Services Application Programming Interface) 是一套类似Kerberos 5的通用网络安全系统接口。该接口是对各种不同的客户端服务器安全机制的封装,以消除安全接口的不同,降低编程难度。但该接口在目标机器无域名解析时会有问题

使用strace查看后发现,ssh在验证完key之后,进行authentication gssapi-with-mic,此时先去连接DNS服务器,在这之后会进行其他操作

[root@192-168-3-40 ~]# ssh -vvv root@192.168.3.44
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to 192.168.3.44 [192.168.3.44] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/identity-cert type -1
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_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3
debug2: fd 3 setting O_NONBLOCK
debug1: SSH2_MSG_KEXINIT sent
debug3: Wrote 960 bytes for a total of 981
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa-cert-v01@openssh.com,ssh-dss-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-dss-cert-v00@openssh.com,ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: mac_setup: found hmac-md5
debug1: kex: server->client aes128-ctr hmac-md5 none
debug2: mac_setup: found hmac-md5
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug3: Wrote 24 bytes for a total of 1005
debug2: dh_gen_key: priv key bits set: 120/256
debug2: bits set: 506/1024
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug3: Wrote 144 bytes for a total of 1149
debug3: check_host_in_hostfile: host 192.168.3.44 filename /root/.ssh/known_hosts
debug3: check_host_in_hostfile: host 192.168.3.44 filename /root/.ssh/known_hosts
debug3: check_host_in_hostfile: match line 8
debug1: Host '192.168.3.44' is known and matches the RSA host key.
debug1: Found key in /root/.ssh/known_hosts:8
debug2: bits set: 527/1024
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: Wrote 16 bytes for a total of 1165
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug3: Wrote 48 bytes for a total of 1213
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /root/.ssh/identity ((nil))
debug2: key: /root/.ssh/id_rsa ((nil))
debug2: key: /root/.ssh/id_dsa ((nil))
debug2: key: /root/.ssh/id_ecdsa ((nil))
debug3: Wrote 64 bytes for a total of 1277
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 gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup gssapi-keyex
debug3: remaining preferred: gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_is_enabled gssapi-keyex
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
debug2: we did not send a packet, disable method
debug3: authmethod_lookup gssapi-with-mic
debug3: remaining preferred: publickey,keyboard-interactive,password
debug3: authmethod_is_enabled gssapi-with-mic
debug1: Next authentication method: gssapi-with-mic
debug3: Trying to reverse map address 192.168.3.44.
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 

debug2: we did not send a packet, disable method
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/identity
debug3: no such identity: /root/.ssh/identity
debug1: Trying private key: /root/.ssh/id_rsa
debug3: no such identity: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug3: no such identity: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug3: no such identity: /root/.ssh/id_ecdsa
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
root@192.168.3.44's password:

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

(0)

相关推荐

  • Linux SSH 安全策略 更改 SSH 端口

    默认的 SSH 端口是 22.强烈建议改成 10000 以上.这样别人扫描到端口的机率也大大下降.修改方法:# 编辑 /etc/ssh/ssh_config vim /etc/ssh/ssh_config # 在 Host * 下 ,加入新的 Port 值.以 18439 为例: Port 22 Port 18439 # 编辑 /etc/ssh/sshd_config (同上2图) vim /etc/ssh/sshd_config #加入新的 Port 值 Port 22 Port 18439

  • ssh自动登录的4种实现方法

    1. 自动ssh/scp方法 A为本地主机(即用于控制其他主机的机器) ;B为远程主机(即被控制的机器Server), 假如ip为192.168.60.110;A和B的系统都是Linux 在A上运行命令:# ssh-keygen -t rsa (连续三次回车,即在本地生成了公钥和私钥,不设置密码)# ssh root@192.168.60.110 "mkdir .ssh" (需要输入密码)# scp ~/.ssh/id_rsa.pub root@192.168.60.110:.ssh/

  • Linux VPS安全设置之一 修改SSH端口(CentOS/Debian)

    老左在之前的不少文章中已经分享过在centos或者在debian环境下安装lnmp和llsmp的教程,老左用人格担保肯定是可行的,因为我都是在实战操作后截图及写下来的文章.可以让VPS初学者手把手的学习如何在Linux VPS上安装系统及建立网站.老左第一次使用VPS不会安装环境,准备请一个网友安装,还准备收费50元,鉴于此我就自学. 我们在学会了VPS的安装和建站之后,肯定需要附带学习VPS的安全设置.因为VPS和主机不同,主机商可能会给我们备份,而且主机的安全性都有主机商承担.但是,如果现在

  • ssh连接超时解决方法

    1.修改server端的etc/ssh/sshd_config 复制代码 代码如下: ClientAliveInterval 60 #server每隔60秒发送一次请求给client,然后client响应,从而保持连接ClientAliveCountMax 3 #server发出请求后,客户端没有响应得次数达到3,就自动断开连接,正常情况下,client不会不响应 2.修改client端的etc/ssh/ssh_config添加以下:(在没有权限改server配置的情形下) 复制代码 代码如下:

  • ssh expect自动登录的脚本代码

    实现:ssh远程登录,每次都要指定一堆用户名和密码,现要求实现自动登录.登录流程:本地A 先登录到 B 再由B 登录到最终的C 如下: 复制代码 代码如下: #!/usr/bin/expect -fset timeout 30spawn ssh Bexpect "password:"send "passwd@\r"expect "]*"send "ssh name@C -p port\r"expect "passwo

  • ssh远程执行命令方法和Shell脚本实例

    写这篇博客之前,我google了一堆相关文章,大都是说修改/etc/sudoers,然后NOPASSWD:指定的cmd,但是真心不管用,没有远程虚拟终端这个方法就是浮云,ubuntu10.04 server 亲测!! ssh执行远程操作 命令格式 复制代码 代码如下: ssh -p $port $user@$p 'cmd'    $port : ssh连接端口号  $user: ssh连接用户名  $ip:ssh连接的ip地址  cmd:远程服务器需要执行的操作 准备工作 基于公私钥认证或者用户

  • Python实现建立SSH连接的方法

    本文实例讲述了Python实现建立SSH连接的方法.分享给大家供大家参考.具体实现方法如下: 我需要实现一个Windows下远程连接到SSH服务器执行命令的功能,所以就在网上找资料.我的环境是:Windows7 64位,Python 2.7 32位.按照网上的说法,需要下载pycrypto和paramiko两个模块进行安装.最后下载的版本是pycrypto2.3和paramiko1.7.6. 安装过程也比较简单,先安装pycrypto后安装paramiko,解压后在命令提示符下切换到解压后的目录

  • SSH整合中 hibernate托管给Spring得到SessionFactory

    <prop key="hibernate.current_session_context_class">thread</prop> 然后 Resource resource=new ClassPathResource("/WEB-INF/applicationContext.xml"); BeanFactory factory=new XmlBeanFactory(resource); SessionFactory sessionFactor

  • SSH 使用原理 与解释

    用SSH替代Telnet 获得更安全连接 如果你一直利用Telnet控制网络设备,你可以考虑采用其他更安全的方式.本文告诉你如何用SSH替换Telnet. Click here to find out more! 使用Telnet这个用来访问远程计算机的TCP/IP协议以控制你的网络设备相当于在离开某个建筑时大喊你的用户名和口令.很快地,会有人进行监听,并且他们会利用你安全意识的缺乏. SSH是替代Telnet和其他远程控制台管理应用程序的行业标准.SSH命令是加密的并以几种方式进行保密. 在使

  • 简单架设SSH+Squid代理服务器的自由上网通道的方法

    而SSH则很好地解决了这个问题.你只需要一个vps,就可以配置了.架设还是挺容易的. 安装webmin webmin是一个可视化管理linux系统的免费软件.我们安装它是为了方便管理squid代理服务器或者linux系统.详细安装地址如下: CentOS 安装Webmin管理系统 安装squid代理服务器 1.在安装squid之前,我们需要安装EPEL软件包. 复制代码 代码如下: rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i38

  • PowerShell小技巧之尝试ssh登录

    在PSNet程序集中继续进行扩展,在$env:PSSpace/PSNet/TCPOp/下创建Invoke-SSHLogin.ps1脚本用于在传入指定ssh地址.用户名和密码后返回是否登录成功. 在$env:PSSpace/PSNet/下创建Lib目录用于存放在脚本中需要使用的第三方库,由于在本文中需要引用Renci.SshNet.dll用户可以从http://sshnet.codeplex.com/releases/view/72214中下载程序,解压后将文件放置在$env:PSSpace/PS

  • shell脚本实现ssh自动登录功能分享

    文件名:ssh_auto_login 复制代码 代码如下: #!/usr/bin/expect### ssh模拟登陆器## @author zhiyuan <hzyhouzhiyuan艾特gmail.com>##if {$argc<4} { puts "Error params: $argv" puts "Expect params :user passwd ip port [translate_id]" exit 1} set default_p

  • SSH+Jquery+Ajax框架整合

    近期学习了SSH2(Struts2+Spring+Hibernate)的整合后,开始尝试的写一个登陆界面,结果发现:若是单单使用struts2来进行页面跳转的话页面的效果不怎么样,同时也无法进行局部刷新(即异步提交验证). 于是,我开始在网上搜索解决的办法,有些说通过一个隐藏的iframe来达到效果,当我总觉得麻烦和不实用.后来问了下老师,告诉了我使用ajax可以达到想要的效果,我又发现网上有很多例子都是ajax的,但缺少的就是SSH2(整合好的)和ajax 的整合(ajax使用了jQuery框

随机推荐