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 ...
随机推荐
- date命令时间戳和时间之间的转换
这里是在mac下的操作,主要就是用date这个命令,更多的用法用man命令查看 字符串格式时间 TO 时间戳我们知道date 命令可以直接把当前时间转化为时间戳 # date +%s143678152 ...
- wamp64显示黄色图标不能忍
哎,昨天硬盘合区了下,重新安装了wamp64,删库的时候忘记备份数据库,灾难啊,只能自己重新建库建表了,深刻的教训啊. 然后还启动后是黄色图标,不能忍啊,发现wamp64需要启动三个服务,mysql, ...
- 【448】NLP, NER, PoS
目录: 停用词 —— stopwords 介词 —— prepositions —— part of speech Named Entity Recognition (NER) 3.1 Stanfor ...
- Appium查询元素方法
Appium查询元素有两种方式 一种是使用UI Automator: 参考 https://www.cnblogs.com/gongxr/p/10906736.html 另一种是使用appium的In ...
- linux修改系统时间和时区
1.修改系统时间linux系统时钟有两个,一个是硬件时钟,即BIOS时间,就是我们进行CMOS设置时看到的时间,另一个是系统时钟,是linux系统Kernel时间.当Linux启动时,系统Kernel ...
- vue地图可视化 ArcGIS篇
ArcGIS for javascript开发心得 本次实例中采用ArcGIS for javascript3.24版本,由于版本3与4在API等存在较大区别,就不一一列举,详细区别看官方解释arcg ...
- python jieba
https://www.cnblogs.com/jiayongji/p/7119065.html 安装 pip install jieba 简单用法 结巴分词分为三种模式:精确模式(默认).全模式和搜 ...
- leetcode腾讯精选练习(50 题)(持续更新)
1.除自身以外数组的乘积 给定长度为 n 的整数数组 nums,其中 n > 1,返回输出数组 output ,其中 output[i] 等于 nums 中除 nums[i] 之外其余各元素的乘 ...
- 13 Spring 的事务控制
1.事务的概念 理解事务之前,先讲一个你日常生活中最常干的事:取钱. 比如你去ATM机取1000块钱,大体有两个步骤:首先输入密码金额,银行卡扣掉1000元钱:然后ATM出1000元钱.这两个步骤必 ...
- Java线程的等待与唤醒完整示例代码
项目结构: 资源类: 输入线程: 输出线程: 测试: 人妖问题发生: 线程安全问题的解决方法: 调用Object的wait()和notify()方法时需注意:必须是锁对象方可调用,否则将抛出无效的监 ...