如何使用受密码保护的 SSL 密钥通过 Rsync 提交文件夹内容?

如何使用受密码保护的 SSL 密钥通过 Rsync 提交文件夹内容?

已建议停止使用 Git 部署到 VPS,我又回到了 Rsync 方法。不幸的是,Rsync 非常不友好,发出不明确的错误有时错误消息与实际错误不匹配。所以,我不指望你会回答什么

rsync: Failed to exec r: No such file or directory (2)
rsync error: error in IPC code (code 14) at pipe.c(85) [sender=3.1.3]
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in IPC code (code 14) at io.c(235) [sender=3.1.3]

方法。

首先我需要检查语法。

我有 VPSUbuntu 22.04和 WSLUbuntu 20.04. 遵循基本的安全要求,在 VPS 中我有:

  1. 创建非root用户
  2. 使用密码创建 SSH 密钥
  3. 禁止任何用户通过密码登录
  4. 完全禁用 root 用户登录

现在需要把本地04-StagingBuild目录的内容部署到var/www/staging.example.comVPS上,可惜的是,我还没找到“统一的正确语法”,这个版本

rsync -azver -i ~/.ssh/Example-Deployer ./04-StagingBuild/ [email protected]:/var/www/staging.example.com

原因

rsync: Failed to exec r: No such file or directory (2)
rsync error: error in IPC code (code 14) at pipe.c(85) [sender=3.1.3]
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in IPC code (code 14) at io.c(235) [sender=3.1.3]

还有版本--rsh=ssh

rsync -azver --rsh=ssh -i~/.ssh/Example-Deployer ./04-StagingBuild/ [email protected]:/var/www/staging.example.com

它导致

[email protected]: Permission denied (publickey).
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(235) [sender=3.1.3]

由于涉及敏感信息,我无法发布实际的终端输出,但我确信所有目录都存在。此外,正常的 SSH 登录工作正常。

如果您需要我检查某些内容,请告诉我——我会提供尽可能多的详细信息。

答案1

-e的选项是rsync(来自man rsync):

--rsh=COMMAND, -e        specify the remote shell to use

[...]

--rsh=COMMAND, -e
   This  option  allows  you  to  choose  an alternative remote shell
   program to use for communication between the local and remote
   copies of rsync.  Typically, rsync is configured to use ssh by default, 
   but you may prefer to use rsh on a local network.

这意味着它需要一个值。而您正在使用,-azver因此-e将其r视为值并尝试执行它。由于没有调用的程序r,因此失败。

选择-i

       --itemize-changes, -i    output a change-summary for all updates

所以-i ~/.ssh/Example-Deployer没有意义。看起来您正在使用另一个程序的命令行选项。我怀疑您正在考虑-i的选项ssh,但这不是-i中的意思rsync。请记住,每个工具都有自己的选项,您永远不应假设含义相同。

现在,如果~/.ssh/Example-Deployer您想使用密钥文件,您可以尝试:

rsync -azvr -e "ssh -i ~/.ssh/Example-Deployer" \
  ./04-StagingBuild/ [email protected]:/var/www/staging.example.com

但是,具体细节取决于您到底想要什么行为。如果您更新问题并解释您希望 rsync 做什么,如果以上内容还不够,我可以更新。

相关内容