scp连接缓慢的解决方法

2017-08-10

scp是linux中很好用的几个命令之一,特别是在服务器之间拷贝文件。但我们在使用scp命令时会遇到敲完命令回车时,连接很慢,要等好久才能出现输入密码的提示符。

1、导致这个问题的主要原因是GSSAPI认证。
用scp -v username@host:file file或者ssh -v user@host
提醒下面的信息时停住了。
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: gssapi-with-mic
这个命令时可以看到gssapi-with-mic这个过程耗时比较长。
2、用scp时加上-o GSSAPIAuthentication=no这个参数,如, scp scp -o GSSAPIAuthentication=no username@host:file file
3、在$HOME/.ssh/config这个文件中加入下面这行参数。
GSSAPIAuthentication no
4、GSSAPI身份验证.
GSSAPIAuthentication 是否允许使用基于 GSSAPI 的用户认证.默认值为"no".仅用于SSH-2.
GSSAPICleanupCredentials 是否在用户退出登录后自动销毁用户凭证缓存。默认值是"yes".仅用于SSH-2.
需要特别注意的是:
GSSAPI是公共安全事务应用程序接口(GSS-API)
公共安全事务应用程序接口以一种统一的模式为使用者提供安全事务,由于它支持最基本的机制和技术,所以保证不同的应用环境下的可移植性.
该规范定义了GSS-API事务和基本元素,并独立于基本的机制和程序设计语言环境,并借助于其它相关的文档规范实现.

如果我们在服务端打开GSSAPIAuthentication配置项,如下:
[root@server ~]#vim /etc/ssh/sshd_config
........
GSSAPIAuthentication yes
GSSAPICleanupCredentials yes

那么在客户端登录服务端会用gssapi-keyex,gssapi-with-mic进行身份校验,同样客户端也要支持这种身份验证,如下:

[root@client ~]#vim /etc/ssh/ssh_config
GSSAPIAuthentication yes
GSSAPIDelegateCredentials yes

我们在客户端连接SSH服务端,如下:
ssh -v 192.168.1.11
.................
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password

我们看到如下的信息:
debug1: Unspecified GSS failure. Minor code may provide more information
No credentials cache found
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
说明SSH登录时采用GSSAPI的方式进行身份验证,但我们的系统不支持.

最后如果我们不用这种方式进行身份验证的话,建议关闭这个选项,这样可以提高验证时的速度.

分类:Linux | 标签: |

相关日志

评论被关闭!