5

linux/scp命令报“bash: scp: command not found lost connection”错误的解决办法

 2 years ago
source link: https://zhang.ge/5027.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

linux/scp命令报“bash: scp: command not found lost connection”错误的解决办法

Jager · 3月27日 · 2015年centos7 · linux · redhat · 操作系統 120次已读

这两天接到的任务是给JAVA开发项目组部署【JAVA+MySQL主从+Redis主从】运行环境。部署过程中大问题倒没有,小问题却不少,因此也涨了不少经验值。后续有时间我会一一整理记录下来,沉淀而不忘分享。

linux/scp命令报“bash: scp: command not found lost connection”错误的解决办法

今天,装完一台redis,并配置好redis.conf后,想偷懒直接用scp传到另一台redis,省去全部重新编辑的麻烦。结果一执行就出现下面这个错误:

bash: scp: command not found

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

yum -y install openssh-clients

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

[root@cache-ns-4 etc]# scp redis.conf [email protected]:/usr/local/redis/etc/
[email protected]'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 [email protected]:/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 *
******此处省略数行******
[email protected]'s password:
debug1: Authentication succeeded (password).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
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 [email protected] 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 [email protected]:/usr/local/redis/etc/
[email protected]'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 的工作流程。

中午时间有限,就写这么多了,希望遇到这个问题的人,看到此文能少走点弯路。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK