scp 出现 subsystem request failed on channel 0 scp: Connection closed 的解决方法

.

.

.

.

.

先说结论,给 scp 命令添加一个 -O (大写字母O,不是数字0)参数就可以了。

--------------------开启故事模式--------------------

最近在使用 Gerrit 下载代码的时候,发现出现这样的错误:

>$ git clone "ssh://user@10.10.10.13:29418/project/manifest" && scp -p -P 29418 user@10.10.10.13:hooks/commit-msg "manifest/.git/hooks/"
Cloning into 'manifest'...
remote: Counting objects: 69, done
remote: Finding sources: 100% (68/68)
remote: Total 1042 (delta 18), reused 1020 (delta 18)
Receiving objects: 100% (1042/1042), 504.61 KiB | 5.00 MiB/s, done.
Resolving deltas: 100% (502/502), done.
subsystem request failed on channel 0
scp: Connection closed

这样去下载代码,git clone 是能够执行成功的,但是后面的 scp 出现了错误。很多小伙伴没有注意到,结果在提交代码的时候报错说找不到 Change-Id。

>$ git push origin HEAD:refs/for/master
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 301 bytes | 301.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Processing changes: refs: 1, done    
remote: ERROR: commit ceee6d1: missing Change-Id in message footer
remote: 
remote: Hint: to automatically insert a Change-Id, install the hook:
remote:   gitdir=$(git rev-parse --git-dir); scp -p -P 29418 user@10.10.10.13:hooks/commit-msg ${gitdir}/hooks/
remote: and then amend the commit:
remote:   git commit --amend --no-edit
remote: 
To ssh://10.10.10.13:29418/project/manifest
 ! [remote rejected] HEAD -> refs/for/master (commit ceee6d1: missing Change-Id in message footer)
error: failed to push some refs to 'ssh://10.10.10.13:29418/project/manifest'

实际上这个错误就是由于在 clone 代码的时候,通过 scp 从服务器下载钩子脚本文件没有成功导致的。

只需要给 scp 命令添加一个 -O (大写字母O,不是数字0)参数就可以成功下载钩子了,完整命令如下:

>$ git clone "ssh://user@10.10.10.13:29418/project/manifest" && scp -O -p -P 29418 user@10.10.10.13:hooks/commit-msg "manifest/.git/hooks/"

根据 scp(1) 的 man 手册的说法,大概是因为服务端比较老旧,没有实现 SFTP 传输协议,通过 -O 参数可以让 scp 命令使用 SCP 协议而不是 SFTP 协议进行传输。

-O      Use  the  legacy  SCP  protocol for file transfers instead of the SFTP protocol.  Forcing the use of the SCP protocol may be necessary for servers that do not implement SFTP, for backwards-compatibility for particular filename wildcard patterns and for expanding paths with a ‘~’ prefix for older SFTP servers.

 

posted on 2024-01-12 10:43  0xCAFEBABE  阅读(625)  评论(0编辑  收藏  举报

导航