如何使用私钥rsync?

Ric*_*ard 8 rsync file-transfer azure ubuntu macos

我正在尝试从我的 MacOS 机器 rsync 到在 Windows Azure 上运行的 Ubuntu 服务器。要 ssh 到它,我必须执行以下操作:

 $ ssh -i  myPrivateKey.key -p 22 me@me.cloudapp.net
Run Code Online (Sandbox Code Playgroud)

我认为密钥文件可能是 X509 公钥,如果有帮助的话(抱歉,我不是系统管理员)。无论如何,我可以使用上述命令成功 ssh。

现在我想将文件同步到远程服务器。我是否需要以.key某种方式提供文件作为选项?

正常的 rsync 命令失败:

$ sudo rsync -avz -e my/file me@me.cloudapp.net:/my/path
    rsync: Failed to exec my/file: Permission denied (13)
rsync error: error in IPC code (code 14) at /SourceCache/rsync/rsync-42/rsync/pipe.c(86) [receiver=2.6.9]
    rsync: connection unexpectedly closed (0 bytes received so far) [receiver]
    rsync error: error in rsync protocol data stream (code 12) at /SourceCache/rsync/rsync-42/rsync/io.c(452) [receiver=2.6.9]
Run Code Online (Sandbox Code Playgroud)

use*_*686 11

命令失败不是因为错误的键,而是因为你告诉 rsync 运行my/file而不是ssh(通过使用-e选项,它会选择后面的单词)。-e首先删除该选项。

由于rsync通常用于ssh连接,您可以将两者配置为始终使用特定密钥连接到 cloudapp。例如,将其放在~/.ssh/config文件的顶部:

Host me.cloudapp.net
    Username me
    IdentityFile ~/my-cloudapp-key.key
    IdentitiesOnly yes
Run Code Online (Sandbox Code Playgroud)

Username me部分还将让您me@在使用 ssh 或 rsync 时跳过添加。平原rsync -avz my/file me.cloudapp.net:/my/path将工作。


注意:SSH 密钥不是 X.509 证书;它们只是普通的 RSA 或 ECDSA 密钥对,没有任何附加信息。

  • 在 Ubuntu 上,它似乎是 `User` 而不是 `Username` (3认同)