Linux 下升级 OpenSSH 到 9.x 版本对 scp 影响

Linux 下升级 OpenSSH 到 9.x 版本对 scp 影响

背景说明

# 升级 openssh 到 9.0 版本后,scp 命令在主机间拷贝文件,出现文件被清空现象
- scp 命令 -- 执行文件拷贝
- 源文件 -- testscp.txt
- 目标文件 -- testscp.txt
- 目标机器、目标路径 -- 本机、当前目录 -- 相当于覆盖拷贝

模拟执行过程

openssh 版本说明
  • openssh 版本
[root@localhost ~]$ ssh -V
OpenSSH_9.0p1, OpenSSL 1.0.2l  25 May 2017
  • openssl 版本
[root@localhost ~]$ openssl version
OpenSSL 1.0.2l  25 May 2017
模拟过程
  • 创建文件
[root@localhost ~]$ echo "111" > testscp.txt
  • 查看文件内容
[root@localhost ~]$ cat testscp.txt 
111
  • 执行 scp 拷贝
# 通过 scp 拷贝 -- 出现未拷贝现象
[root@localhost ~]$ scp testscp.txt root@192.168.68.129:/root/testscp.txt 
testscp.txt                              0%    0     0.0KB/s   --:-- ETA
  • 查看文件内容
# 文件内容为空
[root@localhost ~]$ cat testscp.txt

对比执行差异

OpenSSH 8.x 版本 – 执行 – 成功
  • 执行说明
# 相同机器 -- 相同目录 -- 相同文件名
- openssh 版本 -- 8.x
- 源文件 -- testscp.txt
- 源目录 -- /root/testscp.txt

- 目标主机 -- 当前主机
- 目标文件 -- testscp.txt
- 目标目录 -- /root/testscp.txt

- scp 结果 -- 成功
  • 执行过程
# 使用 scp -vvv -- 观察 scp 过程
debug1: Sending command: scp -v -t /home/dev/testscp.txt
debug2: channel 0: request exec confirm 1
debug3: send packet: type 98
debug2: channel_input_open_confirmation: channel 0: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug2: channel 0: rcvd adjust 2097152
debug3: receive packet: type 99
debug2: channel_input_status_confirm: type 99 id 0
debug2: exec request accepted on channel 0
Sending file modes: C0664 4 testscp.txt
debug2: channel 0: rcvd ext data 26
Sink: C0664 4 testscp.txt
debug2: channel 0: written 26 to efd 6
testscp.txt                                                                                                                                                                                                                100%    4     5.1KB/s   00:00    
debug2: channel 0: read<=0 rfd 4 len 0
debug2: channel 0: read failed
debug2: chan_shutdown_read: channel 0: (i0 o0 sock -1 wfd 4 efd 6 [write])
debug2: channel 0: input open -> drain
debug2: channel 0: ibuf empty
debug2: channel 0: send eof
debug3: send packet: type 96
debug2: channel 0: input drain -> closed
OpenSSH 9.0 版本 – 执行 – 失败
  • 执行说明
# 相同机器 -- 相同目录 -- 相同文件名
- openssh 版本 -- 9.x
- 源文件 -- testscp.txt
- 源目录 -- /root/testscp.txt

- 目标主机 -- 当前主机
- 目标文件 -- testscp.txt
- 目标目录 -- /root/testscp.txt

- scp 结果 -- 失败
  • 执行过程
# 使用 scp -vvv -- 观察 scp 过程 -- 使用 SSH2 协议 -- 执行 scp 失败
scp: debug2: do_upload: upload local "testscp.txt" to remote "/root/testscp.txt"
scp: debug2: Sending SSH2_FXP_OPEN "/root/testscp.txt"
scp: debug3: Sent dest message SSH2_FXP_OPEN I:3 P:/root/testscp.txt M:0x001a
testscp.txt                                                                                                                                                                                                                  0%    0     0.0KB/s   --:-- ETA
scp: debug3: Sent message SSH2_FXP_CLOSE I:4
scp: debug3: SSH2_FXP_STATUS 0
debug2: channel 0: read failed rfd 4 maxlen 32768: Broken pipe
OpenSSH 9.0 版本 – 执行 – 失败
  • 执行说明
# 相同机器 -- 相同目录 -- 相同文件名
- openssh 版本 -- 9.x
- 源文件 -- testscp.txt
- 源目录 -- /root/testscp.txt

- 目标主机 -- 当前主机
- 目标文件 -- testscp.txt
- 目标目录 -- /tmp/testscp.txt

- scp 结果 -- 成功
  • 执行过程
# 使用 scp -vvv -- 观察 scp 过程 -- 使用 SSH2 协议 -- 执行 scp 成功
scp: debug2: do_upload: upload local "testscp.txt" to remote "/tmp/testscp.txt"
scp: debug2: Sending SSH2_FXP_OPEN "/tmp/testscp.txt"
scp: debug3: Sent dest message SSH2_FXP_OPEN I:3 P:/tmp/testscp.txt M:0x001a
testscp.txt                                                                                                                                                                                                                  0%    0     0.0KB/s   --:-- ETA
scp: debug3: Sent message SSH2_FXP_WRITE I:5 O:0 S:4
scp: debug3: SSH2_FXP_STATUS 0
scp: debug3: In write loop, ack for 5 4 bytes at 0
testscp.txt                                                                                                                                                                                                                100%    4    19.1KB/s   00:00    
scp: debug3: Sent message SSH2_FXP_CLOSE I:4
scp: debug3: SSH2_FXP_STATUS 0
debug2: channel 0: read failed rfd 4 maxlen 32768: Broken pipe

解决办法

命令使用
# 添加参数 -O -- scp -O 
[root@localhost ~]$ scp -O testscp.txt root@192.168.68.129:/root/testscp.txt 
testscp.txt                              100%    0     0.0KB/s   00:00
别名配置
# 为 scp 命令增加别名 -- 默认增加参数
[root@localhost ~]$ grep alias /etc/profile
alias scp='scp -O'

参考

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值