解决 linux 下 ssh 远程连接服务卡慢的全过程-亚博电竞手机版
linux
2020年03月29日 23:42
1
连接慢的主要原因是dns解析导致
解决方法:
1、在ssh服务端上更改/etc/ssh/sshd_config文件中的配置为如下内容:
usedns no # gssapi options gssapiauthentication no
然后,执行/etc/init.d/sshd restart重启sshd进程使上述配置生效,在连接一般就不慢了。
2、如果还慢的话,检查ssh服务端上/etc/hosts文件中,127.0.0.1对应的主机名是否和 uname -n的结果一样,或者把本机ip和hostname(uname -n结果)加入到/etc/hosts里。
[root@c64 ~]# uname -n c64 [root@c64 ~]# cat /etc/hosts #modi by oldboy 11:12 2013/9/24 127.0.0.1 c64 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 10.0.0.18 c64 ################
利用ssh -v的调试功能查找慢的原因
其实可以用下面的命令调试为什么慢的细节(学习这个思路很重要)。
[root@c64 ~]# ssh -v root@10.0.0.19 openssh_5.3p1, openssl 1.0.0-fips 29 mar 2010 debug1: reading configuration data /etc/ssh/ssh_config debug1: applying options for * debug1: connecting to 10.0.0.19 [10.0.0.19] port 22. debug1: connection established. debug1: permanently_set_uid: 0/0 debug1: identity file /root/.ssh/identity type -1 debug1: identity file /root/.ssh/id_rsa type -1 debug1: identity file /root/.ssh/id_dsa type -1 debug1: remote protocol version 2.0, remote software version openssh_4.3 debug1: match: openssh_4.3 pat openssh_4* debug1: enabling compatibility mode for protocol 2.0 debug1: local version string ssh-2.0-openssh_5.3 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(1024<1024<8192) 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 '10.0.0.19 (10.0.0.19)' can't be established. rsa key fingerprint is ca:18:42:76:0e:5a:1c:7d:ef:fc:24:75:80:11:ad:f9. are you sure you want to continue connecting (yes/no)? yes =======>老男孩老师评:这里就是提示保存密钥的交互提示。 warning: permanently added '10.0.0.19' (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,password debug1: next authentication method: 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: next authentication method: password root@10.0.0.19's password: =======>老男孩老师评:这里就是提示输入密码的交互提示。 debug1: authentication succeeded (password). debug1: channel 0: new [client-session] debug1: entering interactive session. debug1: sending environment. debug1: sending env lang = en_us.utf-8 last login: tue sep 24 10:30:02 2013 from 10.0.0.18
在远程连接时如果慢就可以确定卡在哪了。
[root@c64_a ~]# ssh -v oldboy@10.0.0.17 openssh_5.3p1, openssl 1.0.0-fips 29 mar 2010 debug1: reading configuration data /etc/ssh/ssh_config debug1: applying options for * debug1: connecting to 10.0.0.17 [10.0.0.17] port 22. debug1: connection established. debug1: permanently_set_uid: 0/0 debug1: identity file /root/.ssh/identity type -1 debug1: identity file /root/.ssh/id_rsa type -1 debug1: identity file /root/.ssh/id_dsa type 2 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 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(1024<1024<8192) 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 '10.0.0.17' is known and matches the rsa host key. debug1: found key in /root/.ssh/known_hosts:2 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
上述配置没配就发现卡到gssapi这。就大概知道是gssapi的问题。
实际上在linux系统优化部分就应该优化ssh服务的此处。
展开全文