首页 > 解决方案 > 使用 rsync 和 ssh keygen

问题描述

我有一个 Debian 服务器,我想制作一个 cron 来将数据从我的服务器保存到连接到我的 mac 的远程硬盘驱动器。

所以,我做了这个正确运行的命令:

rsync -ah -progress -delete -e ssh xxxxxxx@1xx.1xx.1xx.1xx:/var/www/html/AccesBD/file /Volumes/USB-HDD

但我必须输入密码。

我使用 ssh-keygen 制作了文件 id_rsa_lb(不是 id_rsa),然后将其发送

ssh-copy-id -i ~/.ssh/id_rsa_lb.pub 1xx.1xx.1xx.1xx

该命令ssh -i ~/.ssh/id_rsa_lb lxxxxxxxxxx@1xx.1xx.1xx.1xx运行正确,不需要任何密码。没关系。

但是当我尝试使用 ssh/id_rsa_lb 运行 rsync 时,出现错误:

rsync -ah -progress -delete -e ssh -i ~/.ssh/id_rsa_lb lxxxxxxxxx@1xx.1xx.1xx.1xx /var/opt/file /Volumes/USB-HDD

rsync: link_stat "/Users/yyyyy_yyyyy/.ssh/lxxxxxxxxx@1xx.1xx.1xx.1xx" failed: No such file or directory (2)
rsync: link_stat "/var/opt/base.sql" failed: No such file or directory (2)
rsync error: some files could not be transferred (code 23) at /BuildRoot/Library/Caches/com.apple.xbs/Sources/rsync/rsync-54/rsync/main.c(996) [sender=2.6.9]

你能告诉我有什么问题吗?

谢谢

标签: sshdebianssh-keygen

解决方案


使用引号,-e只需要一个参数。

rsync user@host:src_path local_dest_path ... -e "ssh -i ~/.ssh/id_rsa_lb" 

推荐阅读