ssh远程登录连接慢的解决方法
近期在搭建自动化集群服务,写脚本ssh批量分发公钥至其它服务器时比较缓慢,便在度娘上寻找解决方法如下:
方法一:
以ssh -v 调试模式远程登录:
[root@bqh-nfs- ceshi]# ssh -v -p22 root@192.168.43.117 /sbin/ifconfig eth0
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.43.117 [192.168.43.117] 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: 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
debug1: Host '192.168.43.117' is known and matches the RSA host key.
debug1: Found key in /root/.ssh/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
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: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/identity
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Offering public key: /root/.ssh/id_dsa
debug1: Server accepts key: pkalg ssh-dss blen
debug1: read PEM private key done: type DSA
debug1: Authentication succeeded (publickey).
debug1: channel : new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = zh_CN.UTF-
debug1: Sending command: /sbin/ifconfig eth0
eth0 Link encap:Ethernet HWaddr :0C:::FC:1E
inet addr:192.168.43.117 Bcast:192.168.43.255 Mask:255.255.255.0
inet6 addr: :84e5:::20c:29ff:fe71:fc1e/ Scope:Global
inet6 addr: fe80::20c:29ff:fe71:fc1e/ Scope:Link
UP BROADCAST RUNNING MULTICAST MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (233.3 KiB) TX bytes: (82.7 KiB) debug1: client_input_channel_req: channel rtype exit-status reply
debug1: client_input_channel_req: channel rtype eow@openssh.com reply
debug1: channel : free: client-session, nchannels
Transferred: sent , received bytes, in 0.0 seconds
Bytes per second: sent 100007.1, received 121011.8
debug1: Exit status
根据ssh调试信息,观察执行缓慢的开始位置:
- 若在debug1: SSH2_MSG_SERVICE_ACCEPT received (位置①) 开始慢,则需要修改服务端的文件均resolv.conf
- 若在debug1: Next authentication method: gssapi-with-mic (位置②) 开始慢,则需要修改客户端的文件resolv.conf
- 若两者都慢,则客户端和服务端都需要修改文件resolv.conf
方法二:
1、关闭DNS反向解析
在linux中,默认就是开启了SSH的反向DNS解析,这个会消耗大量时间,因此需要关闭。
# vi /etc/ssh/sshd_config
UseDNS=no
2、关闭SERVER上的GSS认证
在authentication gssapi-with-mic有很大的可能出现问题,因此关闭GSS认证可以提高ssh连接速度。
# vi /etc/ssh/sshd_config
GSSAPIAuthentication no
3、修改server上nsswitch.conf文件
# vi /etc/nsswitch.conf
找到
hosts: files dns
改为
hosts:files
hosts: files dns 表示是对于访问的主机进行域名解析的顺序,是先访问file,也就是/etc/hosts文件,如果hosts中没有记录域名,则访问dns,进行域名解析,如果dns也无法访问,就会等待访问超时后返回,因此等待时间比较长。
注意:如果SERVER需要通过域名访问其他服务器,则需要保留此行。
4、打开SERVER上的IgnoreRhosts参数
IgnoreRhosts参数可以忽略以前登录过主机的记录,设置为yes后可以极大的提高连接速度
# vi /etc/ssh/sshd_config
IgnoreRhosts yes
5、修改客户端配置文件ssh_conf(注意,不是sshd_conf)
# vi /etc/ssh/ssh_conf
GSSAPIAuthentication no
ssh远程登录连接慢的解决方法的更多相关文章
- SSH客户端(如PuTTY)ssh远程登录Linux非常慢的解决方法
转:http://blog.useasp.net/archive/2014/05/19/solved-the-problem-of-ssh-client-such-as-putty-remote-lo ...
- linux系统新建用户ssh远程登陆显示-bash-4.1$解决方法
linux系统新建的用户用ssh远程登陆显示-bash-4.1$,不显示用户名路径 网络上好多解决办法,大多是新建.bash_profile文件然后输入XXXXX....然而并没有什么用没有用.... ...
- linux系统新建用户ssh远程登陆显示-bash-4.1$解决方法,ssh-bash-4.1
linux系统新建的用户用ssh远程登陆显示-bash-4.1$,不显示用户名路径 网络上好多解决办法,大多是新建.bash_profile文件然后输入XXXXX....然而并没有什么用没有用.... ...
- remmina从linux远程桌面连接windows失败解决方法
删除如下文件,重新连接 rm ~/.freerdp/known_hosts
- ubuntu拒绝root用户ssh远程登录解决办法
ubuntu拒绝root ssh远程登录通常情况是ssh设置了禁止root远程登录,解决办法就是:修改ssh配置,然后重启ssh服务即可. vi /etc/ssh/sshd_config 找到并用#注 ...
- 【浅层优化实战】ssh远程登录Linux卡慢的全过程排查及解决方案
ssh远程登录Linux卡慢的全过程排查及解决方案 前言: 在linux操作系统使用过程中偶然一次感到使用ssh远程连接软件连接操作系统需要等待许久,第一次没在意,第二次也没在意,第三次有点忍受不住了 ...
- ubuntu18.04配置nvidia docker和远程连接ssh+远程桌面连接(三)
ubuntu18.04配置nvidia docker和远程连接ssh+远程桌面连接(三) 本教程适用于想要在远程服务器上配置docker图形界面用于深度学习的用户. (三)配置远程桌面连接访问dock ...
- ssh远程无法连接VM中的Ubuntu问题
Ubuntu ssh远程无法连接问题 1. 检查sudo ps -e|grep ssh 查看是否有ssh进程服务,如果没有的话,需要下载安装 sudo apt-get install openss ...
- phpmyadmin #2003 无法登录 MySQL服务器的解决方法
本文章向大家介绍phpmyadmin #2003 无法登录 MySQL服务器的解决方法,需要的码农可以参考一下. 通过phpmyadmin连接mysql数据库时提示:"2003 无法登录 M ...
随机推荐
- checkbox与label内的文字垂直居中的解决方案
<label style="float:left;margin-top:5px;margin-left:10px;cursor:pointer"><input t ...
- 进行编译时提示'error: unrecognized command line option "-std=gnu11"'如何处理?
答: 说明编译器不支持此选项,那么在Makefile中替换此选项-std=gnu11 替换成-std=gnu99或-std=c99或-std=c11等,主要看编译器都支持哪些编译选项,笔者的支持-st ...
- 从安装PHP到第一个tomcat执行的hello world其实没那么难
001 初入门的朋友问我为什么她的PHP老是不能安装运行成功,作为一个乐(shi)于(li)助(liao)人(mei)的半程序员, 自然是要好好研究然后手把手教妹纸了! 002 话不多说,进入正题 为 ...
- activiti 自定义用户
https://blog.csdn.net/meng564764406/article/details/53789958 此文目的: 对网络上的关于对activiti 使用做一个总结,因为很难找到一个 ...
- ISO/IEC 9899:2011 条款6——语言
6 语言 6.1 标记法 1.在本条款中所使用的语法标记法.语义类别(非终结符)用斜体字指示,而字面量单词以及字符集成员(终结符)用粗体字指示.跟在一个非终结符后面的冒号(:)引出其定义.在单独的行中 ...
- [LeetCode] 685. Redundant Connection II 冗余的连接之 II
In this problem, a rooted tree is a directed graph such that, there is exactly one node (the root) f ...
- 【SSH进阶之路】Spring的IOC逐层深入——源码解析之IoC的根本BeanFactory(五)
我们前面的三篇博文,简单易懂的介绍了为什么要使用IOC[实例讲解](二).和Spring的IOC原理[通俗解释](三)以及依赖注入的两种常用实现类型(四),这些都是刚开始学习Spring IoC容器时 ...
- 主机可以ping通虚拟机,虚拟机ping不通主机和外网
vmware-->编辑-->虚拟网络编辑器-->更改配置,如下图选择:
- Git设定不合并的文件
一个最简单的做法,通过添加.gitattributes文件来完成 1 在要被合并的分支中设置 git config --global merge.ours.driver true设置git配置项mer ...
- Python的线程、进程和协程
进程:一个进程就是一个正在运行的程序,它是计CPU分配资源的最小单位.每个进程都有自己独立的内存空间.能同时执行的进程数最多不超过内核数,也就是每个内核 同一时刻只能执行一个进程.那么多进程就是能[同 ...