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

连接慢的主要原因是DNS解析导致

解决方法:

1、在ssh服务端上更改/etc/ssh/sshd_config文件中的配置为如下内容:

  1. UseDNS no
  2. # GSSAPI options
  3. GSSAPIAuthentication no

然后,执行/etc/init.d/sshd restart重启sshd进程使上述配置生效,在连接一般就不慢了。

2、如果还慢的话,检查ssh服务端上/etc/hosts文件中,127.0.0.1对应的主机名是否和 uname -n的结果一样,或者把本机ip和hostname(uname -n结果)加入到/etc/hosts里。

  1. [root@C64 ~]# uname -n
  2. C64
  3. [root@C64 ~]# cat /etc/hosts
  4. #modi by oldboy 11:12 2013/9/24
  5. 127.0.0.1 C64 localhost localhost.localdomain localhost4 localhost4.localdomain4
  6. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  7. 10.0.0.18 C64
  8. ################

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

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

  1. [root@C64 ~]# ssh -v root@10.0.0.19
  2. OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010
  3. debug1: Reading configuration data /etc/ssh/ssh_config
  4. debug1: Applying options for *
  5. debug1: Connecting to 10.0.0.19 [10.0.0.19] port 22.
  6. debug1: Connection established.
  7. debug1: permanently_set_uid: 0/0
  8. debug1: identity file /root/.ssh/identity type -1
  9. debug1: identity file /root/.ssh/id_rsa type -1
  10. debug1: identity file /root/.ssh/id_dsa type -1
  11. debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
  12. debug1: match: OpenSSH_4.3 pat OpenSSH_4*
  13. debug1: Enabling compatibility mode for protocol 2.0
  14. debug1: Local version string SSH-2.0-OpenSSH_5.3
  15. debug1: SSH2_MSG_KEXINIT sent
  16. debug1: SSH2_MSG_KEXINIT received
  17. debug1: kex: server->client aes128-ctr hmac-md5 none
  18. debug1: kex: client->server aes128-ctr hmac-md5 none
  19. debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
  20. debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
  21. debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
  22. debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
  23. The authenticity of host '10.0.0.19 (10.0.0.19)' can't be established.
  24. RSA key fingerprint is ca:18:42:76:0e:5a:1c:7d:ef:fc:24:75:80:11:ad:f9.
  25. Are you sure you want to continue connecting (yes/no)? yes
  26. =======>老男孩老师评:这里就是提示保存密钥的交互提示。
  27. Warning: Permanently added '10.0.0.19' (RSA) to the list of known hosts.
  28. debug1: ssh_rsa_verify: signature correct
  29. debug1: SSH2_MSG_NEWKEYS sent
  30. debug1: expecting SSH2_MSG_NEWKEYS
  31. debug1: SSH2_MSG_NEWKEYS received
  32. debug1: SSH2_MSG_SERVICE_REQUEST sent
  33. debug1: SSH2_MSG_SERVICE_ACCEPT received
  34. debug1: Authentications that can continue: publickey,password
  35. debug1: Next authentication method: publickey
  36. debug1: Trying private key: /root/.ssh/identity
  37. debug1: Trying private key: /root/.ssh/id_rsa
  38. debug1: Trying private key: /root/.ssh/id_dsa
  39. debug1: Next authentication method: password
  40. root@10.0.0.19's password:
  41. =======>老男孩老师评:这里就是提示输入密码的交互提示。
  42. debug1: Authentication succeeded (password).
  43. debug1: channel 0: new [client-session]
  44. debug1: Entering interactive session.
  45. debug1: Sending environment.
  46. debug1: Sending env LANG = en_US.UTF-8
  47. Last login: Tue Sep 24 10:30:02 2013 from 10.0.0.18

在远程连接时如果慢就可以确定卡在哪了。

  1. [root@C64_A ~]# ssh -v oldboy@10.0.0.17
  2. OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010
  3. debug1: Reading configuration data /etc/ssh/ssh_config
  4. debug1: Applying options for *
  5. debug1: Connecting to 10.0.0.17 [10.0.0.17] port 22.
  6. debug1: Connection established.
  7. debug1: permanently_set_uid: 0/0
  8. debug1: identity file /root/.ssh/identity type -1
  9. debug1: identity file /root/.ssh/id_rsa type -1
  10. debug1: identity file /root/.ssh/id_dsa type 2
  11. debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
  12. debug1: match: OpenSSH_5.3 pat OpenSSH*
  13. debug1: Enabling compatibility mode for protocol 2.0
  14. debug1: Local version string SSH-2.0-OpenSSH_5.3
  15. debug1: SSH2_MSG_KEXINIT sent
  16. debug1: SSH2_MSG_KEXINIT received
  17. debug1: kex: server->client aes128-ctr hmac-md5 none
  18. debug1: kex: client->server aes128-ctr hmac-md5 none
  19. debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
  20. debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
  21. debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
  22. debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
  23. debug1: Host '10.0.0.17' is known and matches the RSA host key.
  24. debug1: Found key in /root/.ssh/known_hosts:2
  25. debug1: ssh_rsa_verify: signature correct
  26. debug1: SSH2_MSG_NEWKEYS sent
  27. debug1: expecting SSH2_MSG_NEWKEYS
  28. debug1: SSH2_MSG_NEWKEYS received
  29. debug1: SSH2_MSG_SERVICE_REQUEST sent
  30. debug1: SSH2_MSG_SERVICE_ACCEPT received
  31. debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
  32. debug1: Next authentication method: gssapi-keyex
  33. debug1: No valid Key exchange context
  34. debug1: Next authentication method: gssapi-with-mic

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

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

原文发布时间:2015-05-24

本文来自云栖合作伙伴“linux中国”

SSH 远程连接服务慢的解决方案相关推荐

  1. Linux配置ssh远程连接服务

    Linux配置ssh远程连接服务 直接上命令: sudo apt-get update sudo apt-get remove --purge openssh-client sudo apt inst ...

  2. SSH远程连接服务(五)

    文章目录 1. 端口号 2. ssh与telnet区别 3. telnet服务 4. ssh相关命令 4.1 ssh命令 4.2 scp远程拷贝命令 4.3 rz和sftp 5. 在Linux中ssh ...

  3. SSH远程连接服务详解

    远程连接服务器 一,远程连接服务器简介 1.什么是远程连接服务器 远程连接服务器通过文字或图形接口方式来远程登录系统,让你在远程终端前登录 linux 主机以取得可操作主机接口(shell),而登录后 ...

  4. ssh远程连接服务器

    文章目录 第三章 远程连接服务器 1.1 远程连接服务器简介 1.2 连接加密技术简介 1.3 ssh远程连接服务简介 1.4 sftp用法介绍 1.5 实验 作业: 第一题:两台机器:第一台机器作为 ...

  5. 第四章:ssh远程连接服务器

    目录 远程连接服务器简介ssh 连接加密技术简介 非对称加密的一对密钥位置路径 SSH工作流程: 一.版本协商阶段 二.密钥和算法协商阶段 会话密钥的生成: 三.认证阶段 SSH提供两种认证方法: s ...

  6. 【已解决】linux ssh 远程连接服务器,出现登陆慢、打字卡顿输入卡顿解决方案

    目录&索引 问题描述 解决方案 登陆慢 方法 1:修改配置文件 nsswitch_conf 方法 2:修改配置文件 sshd_config UseDNS 方法 3:修改配置文件 sshd_co ...

  7. ssh远程连接不上服务的处理过程总结

    误操作: ps -ef|grep tomcat 将sshd服务的查询了出来 将sshd服务的服务关掉了 所以通过ssh远程连接就会连接不上 处理过程: 1通过阿里云账号登陆控制台 登陆终端  关掉防火 ...

  8. 云计算Linux运维——基础服务应用——SSH远程连接(1)

    点关注不迷路 目录 点关注不迷路 SSH远程连接 一.SSH介绍 1.管理Linux服务器的方式 2.确保Linux服务正常运行 3.客户端软件 二.ssh远程连接操作 1.ssh远程连接 2.执行远 ...

  9. 阿里云ssh远程连接短时间就会断掉的解决方案

    文章目录 问题重现 问题分析 问题解决 打开sshd的配置文件 修改如下参数 重启服务: 补充 总结 问题重现 阿里云服务器,使用Finalshell远程连接,在操作中没有出现任务异常,只要远程连接过 ...

最新文章

  1. Android之Socket通信、List加载更多、Spinner下拉列表
  2. canvas写的一个刮奖效果
  3. linux top 看硬盘读写,linux iotop 安装使用教程(显示硬盘IO读写情况)
  4. 计算机组成原理与接口技术 pdf,计算机组成原理与接口技术课件 7-Datapath(2).pdf...
  5. 工作失职的处理决定_工作失职的处理决定
  6. VirtualBox上编译android遇到共享文件夹引起的问题
  7. 利用Pin分析程序的动态行为特征
  8. 用word保存出高清的pdf文件
  9. 【ajax】6.IE缓存问题解决
  10. RuntimeError: latex was not able to process the following string: b‘lp‘
  11. 升级wamp的php版本,Wamp升级PHP版本
  12. 英语六级常考核心词汇01
  13. Empty filename passed to function
  14. Java算法每日练习
  15. Python爬虫实训案例之爬取豆瓣电影Top250并保存至excel
  16. java 奇数trun_N26-博客作业-week15
  17. 887-三维形体投影面积
  18. SpringSecurity启动器
  19. 最长黑白相间连续串(有规律)
  20. 如何做数据分析,数据分析流程是什么?

热门文章

  1. 如何在MySQL中设置外键约束以及外键的作用
  2. [Java2入门经典]第9章 访问文件和目录
  3. 设置Discuz 7论坛游客可以查看图片,但不能下载附件.
  4. FluorineFx对于现有站点的配置
  5. vscode java settings设置_兼容vscode插件的主题服务
  6. mysql数据库的服务无法启动,mysql服务无法启动,服务没有报告任何错误
  7. A - C语言实验——最值
  8. android系统应用程序,Android调用系统应用程序
  9. java 正则 pattern 线程安全_(一)Java Pattern类----java正则
  10. java检查变量是否定义_JavaScript检查变量是否存在(已定义/初始化)