一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

scp命令报“bash: scp: command not found lost connection”解决办法

时间:2015-04-17 编辑:简简单单 来源:一聚教程网


在进行scp时报bash: scp: command not found
[root@51ou.com add_admin]# scp ocp_admin_privileges.mysql root@10.10.1.128:/root
root@10.10.1.128's password:
bash: scp: command not found
lost connection

查看本机是否安装openssh-clients软件包

[root@51ou.com add_admin]# rpm -q openssh-clients

如果没有我们需要安装

所有机器我都是最小化安装,所以很多组件没装也是情理之中,所以用yum装一下scp:

yum -y install openssh-clients

装完后,继续执行之前的命令,结果出现如下错误:


[root@cache-ns-4 etc]# scp redis.conf root@192.168.17.125:/usr/local/redis/etc/
root@192.168.17.125's password:
bash: scp: command not found
lost connection
[root@cache-ns-4 etc]# whereis scp
scp: /usr/bin/scp /usr/share/man/man1/scp.1.gz

我擦,这就诡异了!明明装了为毛提示不存在呢? 而且还提示输入密码了,用whereis也能找到scp,没办法从man中找到一个DEBUG参数 -v,于是如下增加 -v 参数执行试试:

[root@cache-ns-4 etc]# /usr/bin/scp -v  redis.conf root@192.168.17.125:/usr/local/redis/etc/
Executing: program /usr/bin/ssh host 192.168.17.125, user root, command scp -v -t /usr/local/redis/etc/
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
******此处省略数行******
root@192.168.17.125's password:
debug1: Authentication succeeded (password).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
#关键信息来了,这边将scp命令send到对方,对方提示scp没找到,原因水落石出!
debug1: Sending command: scp -v -t /usr/local/redis/etc/
bash: scp: command not found
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
debug1: channel 0: free: client-session, nchannels 1
debug1: fd 0 clearing O_NONBLOCK
debug1: fd 1 clearing O_NONBLOCK
Transferred: sent 1624, received 2096 bytes, in 0.2 seconds
Bytes per second: sent 9088.1, received 11729.5
debug1: Exit status 127
lost connection
[root@cache-ns-4 etc]#

原来是因为目标主机也没装scp,倒是我大意了!登陆后再次执行如下命令安装scp:


yum -y install openssh-clients

回到之前的服务器上,执行最初的命令,果然毫无意外成功了:


[root@cache-ns-4 etc]# /usr/bin/scp  redis.conf root@192.168.17.125:/usr/local/redis/etc/
root@192.168.17.125's password:
redis.conf                                                                                        100%   35KB  35.3KB/s   00:00
[root@cache-ns-4 etc]#

网站搜索这个故障,大部分经验都是告知要安装scp,然后给出一个 yum 在线安装 scp 的命令。实际上,明明已经提示要输入密码了,说明 scp 是正常安装的!还继续报找不到命令,我们就只能从 scp 的执行过程来分析了,因此就借助到了scp的debug参数(-v),很清楚的看到了整个执行过程,从而得知真正的原因是对方主机没有安装scp,而且还可以清楚的看到 scp 的工作流程。

热门栏目