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


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

    背景说明

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

    模拟执行过程

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

    对比执行差异

    OpenSSH 8.x 版本 – 执行 – 成功
    • 执行说明
    # 相同机器 -- 相同目录 -- 相同文件名
    - openssh 版本 -- 8.x
    - 源文件 -- testscp.txt
    - 源目录 -- /root/testscp.txt
    
    - 目标主机 -- 当前主机
    - 目标文件 -- testscp.txt
    - 目标目录 -- /root/testscp.txt
    
    - scp 结果 -- 成功
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 执行过程
    # 使用 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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    OpenSSH 9.0 版本 – 执行 – 失败
    • 执行说明
    # 相同机器 -- 相同目录 -- 相同文件名
    - openssh 版本 -- 9.x
    - 源文件 -- testscp.txt
    - 源目录 -- /root/testscp.txt
    
    - 目标主机 -- 当前主机
    - 目标文件 -- testscp.txt
    - 目标目录 -- /root/testscp.txt
    
    - scp 结果 -- 失败
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 执行过程
    # 使用 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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    OpenSSH 9.0 版本 – 执行 – 失败
    • 执行说明
    # 相同机器 -- 相同目录 -- 相同文件名
    - openssh 版本 -- 9.x
    - 源文件 -- testscp.txt
    - 源目录 -- /root/testscp.txt
    
    - 目标主机 -- 当前主机
    - 目标文件 -- testscp.txt
    - 目标目录 -- /tmp/testscp.txt
    
    - scp 结果 -- 成功
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 执行过程
    # 使用 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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    解决办法

    命令使用
    # 添加参数 -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
    
    • 1
    • 2
    • 3
    别名配置
    # 为 scp 命令增加别名 -- 默认增加参数
    [root@localhost ~]$ grep alias /etc/profile
    alias scp='scp -O'
    
    • 1
    • 2
    • 3

    参考

  • 相关阅读:
    Gradient conjugate priors and multi-layer neural networks
    20240309-1-校招前端面试常见问题-前端框架及常用工具
    工业交换机的单模多模是什么意思?
    基于Vue+ELement搭建登陆注册页面实现后端交互
    【WebService笔记03】WebService接口开发之WSDL文档
    数据趣事:历史最高温的是新疆吐鲁番?重庆45℃高温仅排全国第二
    [机缘参悟-38]:鬼谷子-第五飞箝篇 - 警示之一:有一种杀称为“捧杀”
    高耗能工厂实现ESG能源管控的策略与实践-天拓四方
    controller调用service层报错Invalid bound statement (not found)
    学周刊杂志学周刊杂志社学周刊编辑部2022年第24期目录
  • 原文地址:https://blog.csdn.net/u010766726/article/details/128144161