rsync scp无法使用,踩坑破解之道!

问题

scp 文件或目录 无反应

rsync 报错

protocol version mismatch -- is your shell clean?
(see the rsync manpage for an explanation)
rsync error: protocol incompatibility (code 2) at compat.c(622) [sender=3.2.7]

以为是版本问题,其实根本不是(别问我是怎么知道,问就是我用了半天的时间手动安装升级成功了,但然并卵)

参考文章

protocol version mismatch — is your shell clean? – 月下博客

文中提到

仔细看命令参数,确认不存在错误。上网查了一下,似乎没说具体原因。于是根据错误提示,用 man 查看 rsync 文档,搜索 “mismatch”,发现如下说明:

rsync occasionally produces error messages that may seem a little cryptic. The one that
seems to cause the most confusion is "protocol version mismatch -- is your shell clean?".

This message is usually caused by your startup scripts or remote shell facility producing
unwanted garbage on the stream that rsync is using for its transport. The way to diagnose
this problem is to run your remote shell like this:

ssh remotehost /bin/true > out.dat

then look at out.dat. If everything is working correctly then out.dat should be a zero
length file. If you are getting the above error from rsync then you will probably find that
out.dat contains some text or data. Look at the contents and try to work out what is pro‐
ducing it. The most common cause is incorrectly configured shell startup scripts (such as
.cshrc or .profile) that contain output statements for non-interactive logins.

看来这个错误比较常见,因此特意说明了原因及测试方法。根据文档提示,原因可能是 .bashrc 等文件中输出了内容。登录到新买的vps,打开 .bashrc,果然看到这么一段:cat /etc/motd。不管 /etc/motd 有没有内容,这条语句都会让shell连过去时输出一行。

找到了原因,解决办法也很简单:注释掉输出语句。再回过头测试 rsync,按照预期进行文件同步,一切正常。

解决之道

这说明什么,当通过ssh远程同步或复制时,连上后,提示信息干扰了传输!

这个目标主机是欧拉服务器,有这么个信息,上图:

欧拉openEuler系统的关键点

找半天,终于:/etc/profile.d/system-info.sh 是这东西搞的鬼!

备份文件后世界核平~

cd /etc/profile.d/
mv system-info.sh system-info.shbak

其它可能产生干扰的地方:

~/.bash_profile

~/.bashrc

/etc/motd

### 使用 SCPRsync 命令从 Windows 传输 .pt 文件到 Ubuntu 虚拟机并保持文件格式正确 为了确保 `.pt` 文件在从 Windows 系统传输到 Ubuntu 虚拟机时不会出现格式问题,可以使用 SCPRsync 命令。以下是具体方法: #### 使用 SCP 命令传输文件 SCP(Secure Copy Protocol)是一种基于 SSH 的安全文件传输协议。以下为命令示例: ```bash scp "C:\path\to\your\model.pt" username@ubuntu_ip:/target/path/ ``` - `C:\path\to\your\model.pt`:Windows 系统中 `.pt` 文件的完整路径[^1]。 - `username`:Ubuntu 虚拟机的用户名。 - `ubuntu_ip`:Ubuntu 虚拟机的 IP 地址。 - `/target/path/`:目标存储路径。 此命令将直接通过 SSH 协议传输文件,避免了因共享文件夹或图形界面操作导致的扩展名误判问题。 #### 使用 Rsync 命令传输文件 Rsync 是一种高效的文件同步工具,支持增量传输和元信息同步。以下为常用命令示例: ```bash rsync -av "C:\path\to\your\model.pt" username@ubuntu_ip:/target/path/ ``` - `-a`:归档模式,保留文件属性和权限。 - `-v`:显示详细输出。 - 其他参数可根据需求调整,例如添加 `--progress` 显示传输进度[^2]。 若需要从远程设备将文件同步回本地,可使用以下命令: ```bash rsync -av username@ubuntu_ip:/source/path/model.pt /local/path/ ``` #### 验证文件完整性 无论使用 SCP 还是 Rsync,传输完成后都应验证文件完整性。可以通过计算 MD5 值进行对比: ```bash certutil -hashfile "C:\path\to\your\model.pt" MD5 # 在 Windows 上计算 md5sum /target/path/model.pt # 在 Ubuntu 上计算 ``` 如果两者的 MD5 值一致,则说明文件传输成功且未损坏[^3]。 #### 注意事项 - 确保 Ubuntu 虚拟机已启用 SSH 服务,并允许通过网络访问。 - 如果遇到权限问题,可以尝试在命令前加上 `sudo` 提升权限。 - 若目标路径不存在,需提前创建目录。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值