博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux下SSH远程连接服务慢解决方案
阅读量:6001 次
发布时间:2019-06-20

本文共 4499 字,大约阅读时间需要 14 分钟。

linux下SSH远程连接服务慢解决方案

1、适用命令及方案如下:

【远程连接及执行命令】
ssh -p22
ssh -p22 /sbin/ifconfig
【远程拷贝:推送及拉取】
scp -P22 -r -p /etc
scp -P22 -r -p /etc
【安全的FTP功能】
sftp -oPort=22
【无密码验证方案】
例如利用sshkey批量分发文件,执行部署操作。

2、连接慢的主要原因是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 -nC64[root@C64 ~]# cat /etc/hosts#modi by oldboy 11:12 2013/9/24127.0.0.1   C64 localhost localhost.localdomain localhost4 localhost4.localdomain4::1         localhost localhost.localdomain localhost6 localhost6.localdomain610.0.0.18   C64################

3、利用ssh-v的调试功能查找慢的原因

其实可以用下面的命令调试为什么慢的细节(学习这个思路很重要)。

[root@C64 ~]# ssh -v root@10.0.0.19OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010debug1: Reading configuration data /etc/ssh/ssh_configdebug1: Applying options for *debug1: Connecting to 10.0.0.19 [10.0.0.19] port 22.debug1: Connection established.debug1: permanently_set_uid: 0/0debug1: identity file /root/.ssh/identity type -1debug1: identity file /root/.ssh/id_rsa type -1debug1: identity file /root/.ssh/id_dsa type -1debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3debug1: match: OpenSSH_4.3 pat OpenSSH_4*debug1: Enabling compatibility mode for protocol 2.0debug1: Local version string SSH-2.0-OpenSSH_5.3debug1: SSH2_MSG_KEXINIT sentdebug1: SSH2_MSG_KEXINIT receiveddebug1: kex: server->client aes128-ctr hmac-md5 nonedebug1: kex: client->server aes128-ctr hmac-md5 nonedebug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sentdebug1: expecting SSH2_MSG_KEX_DH_GEX_GROUPdebug1: SSH2_MSG_KEX_DH_GEX_INIT sentdebug1: expecting SSH2_MSG_KEX_DH_GEX_REPLYThe 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 correctdebug1: SSH2_MSG_NEWKEYS sentdebug1: expecting SSH2_MSG_NEWKEYSdebug1: SSH2_MSG_NEWKEYS receiveddebug1: SSH2_MSG_SERVICE_REQUEST sentdebug1: SSH2_MSG_SERVICE_ACCEPT receiveddebug1: Authentications that can continue: publickey,passworddebug1: Next authentication method: publickeydebug1: Trying private key: /root/.ssh/identitydebug1: Trying private key: /root/.ssh/id_rsadebug1: Trying private key: /root/.ssh/id_dsadebug1: Next authentication method: passwordroot@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-8Last login: Tue Sep 24 10:30:02 2013 from 10.0.0.18在远程连接时如果慢就可以确定卡在哪了。[root@C64_A ~]# ssh -v oldboy@10.0.0.17OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010debug1: Reading configuration data /etc/ssh/ssh_configdebug1: Applying options for *debug1: Connecting to 10.0.0.17 [10.0.0.17] port 22.debug1: Connection established.debug1: permanently_set_uid: 0/0debug1: identity file /root/.ssh/identity type -1debug1: identity file /root/.ssh/id_rsa type -1debug1: identity file /root/.ssh/id_dsa type 2debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3debug1: match: OpenSSH_5.3 pat OpenSSH*debug1: Enabling compatibility mode for protocol 2.0debug1: Local version string SSH-2.0-OpenSSH_5.3debug1: SSH2_MSG_KEXINIT sentdebug1: SSH2_MSG_KEXINIT receiveddebug1: kex: server->client aes128-ctr hmac-md5 nonedebug1: kex: client->server aes128-ctr hmac-md5 nonedebug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sentdebug1: expecting SSH2_MSG_KEX_DH_GEX_GROUPdebug1: SSH2_MSG_KEX_DH_GEX_INIT sentdebug1: expecting SSH2_MSG_KEX_DH_GEX_REPLYdebug1: Host '10.0.0.17' is known and matches the RSA host key.debug1: Found key in /root/.ssh/known_hosts:2debug1: ssh_rsa_verify: signature correctdebug1: SSH2_MSG_NEWKEYS sentdebug1: expecting SSH2_MSG_NEWKEYSdebug1: SSH2_MSG_NEWKEYS receiveddebug1: SSH2_MSG_SERVICE_REQUEST sentdebug1: SSH2_MSG_SERVICE_ACCEPT receiveddebug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,passworddebug1: Next authentication method: gssapi-keyexdebug1: No valid Key exchange contextdebug1: Next authentication method: gssapi-with-mic

上述配置没配就发现卡到gssapi这。就大概知道是gssapi的问题。

实际上在linux系统优化部分就应该优化SSH服务的此处。

转载地址:http://xcbmx.baihongyu.com/

你可能感兴趣的文章
洛谷⑨月月赛Round2 P3393逃离僵尸岛[最短路]
查看>>
群晖NAS使用Docker安装迅雷离线下载出现the active key is not valid.
查看>>
spring boot 2使用Mybatis多表关联查询
查看>>
Making HTTP requests via telnet - Tony's Place
查看>>
千元机市场再添“新宠”,红米Note7和vivo Z3谁才是千元王者
查看>>
荣耀10GT升级EMUI 9.0体验分享:这可能是最好用的手机操作系统
查看>>
ZStack基于华芯通打造ARM国产云平台 助力云上贵州多项应用
查看>>
200本“保护日记”记录黄山迎客松生长变化
查看>>
多方力量携手呵护“中华水塔”青海三江源
查看>>
互联网的下一波红利在哪里?
查看>>
拿姐姐身份证登记结婚竟然成了!婚姻户籍信息共享难在哪儿
查看>>
恒大造车加速,联手柯尼塞格打造顶级新能源车
查看>>
JAVA大神说一个例子让你几分钟学会Annotation
查看>>
富士康要用机器人生产iPhone了?那么多工人怎么办?
查看>>
Python获取当前页面内的所有链接的五种方法
查看>>
【进阶2-3期】JavaScript深入之闭包面试题解
查看>>
【Chrome扩展开发】定制HTTP请求响应头域
查看>>
利用 CocoaPod 和 Git 管理组件中的一些细节梳理
查看>>
聊聊storm trident spout的_maxTransactionActive
查看>>
面向Vue新人:写一个简单的倒计时按钮
查看>>