ssh远程登录很慢的解决方法

发布时间:2020-02-27编辑:脚本学堂
遇到过ssh远程连接很慢的情况吗?遇到这样的问题应该如何解决呢?如果你正有此困苦,就请参考本文给出的具体解决办法吧。

就经验来讲,ssh远程登录慢,这种延迟绝大部分是 GSSAPI 的认证功所导致。
可以用 -v 选项确认这种情况。

例如,以下这个详细登陆过程:
 

复制代码 代码示例:

[root@root ~]# ssh -v root@192.168.15.120
...
...
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
No credentials cache found
 
debug1: Unspecified GSS failure.  Minor code may provide more information
No credentials cache found

debug1: Unspecified GSS failure.  Minor code may provide more information

debug1: Next authentication method: publickey
debug1: Trying private key: /home/root/.ssh/identity
debug1: Trying private key: /home/root/.ssh/id_rsa
debug1: Trying private key: /home/root/.ssh/id_dsa
debug1: Next authentication method: password
root@192.168.15.120's password:
 

解决方法:
当然是要禁用GSSAPI了。

注意:以下方法,在客户端 OpenSSH_4.7p1 centos5.8 centos6.2下测试通过。

1,连接时用命令指定:
 

复制代码 代码示例:
ssh -o GSSAPIAuthentication=no root@192.168.15.127
 

2,在 ssh 客户端程序的配置文件里显式禁用 GSSAPI 认证. 如, 编辑 /etc/ssh/ssh_config 文件, 添加或修改使其有如下一行:
 

复制代码 代码示例:
GSSAPIAuthentication no
 

3,在用户根目录下的 .ssh 目录下创建一个 config 文件. 如, 编辑 /home/root/.ssh/config (如果该文件不存在, 则创建之), 添加选项:
 

复制代码 代码示例:
GSSAPIAuthentication no
 

注意:
A. /etc/ssh/ssh_config 是全局配置文件, 对其进行的修改会影响所有使用 ssh 客户端的系统用户。
B. /home/cherry/.ssh/config 是只会影响用户 xcl 的本地 ssh 客户端配置文件。该文件的所有配置参数会覆盖全局配置文件的相同配置参数。
在禁用 GSSAPI 后, ssh 的登陆提示 "回归" 正常了:
 

复制代码 代码示例:
[root@root ~]# ssh -v root@192.168.15.127
...
...
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Trying private key: /home/root/.ssh/identity
debug1: Trying private key: /home/root/.ssh/id_rsa
debug1: Trying private key: /home/root/.ssh/id_dsa
debug1: Next authentication method: password
root@192.168.15.127's password:

由此可见,不使用GSSAPI的情况下,ssh连接速度,那是相当之快了。
脚本学堂,祝大家学习进步。