如何通过 rsync 使用身份文件?
如何通过 rsync 使用身份文件?
这是我认为我应该与 rsync 一起使用以使用身份文件进行连接的语法:
rsync -avz -e 'ssh -p1234 -i ~/.ssh/1234-identity' \ "/local/dir/" [email protected]:"/remote/dir/"
但它给了我一个错误:
Warning: Identity file ~/.ssh/1234-identity not accessible: No such file or directory.
文件很好,权限设置正确,它在执行 ssh 时有效 -只是不使用 rsync - 至少在我的语法中。我做错了什么?它是否试图在远程计算机上查找身份文件?如果是这样,我如何指定要在我的本地计算机上使用身份文件?
How do you use an identity file with rsync?
This is the syntax I think I should be using with rsync to use an identity file to connect:
rsync -avz -e 'ssh -p1234 -i ~/.ssh/1234-identity' \ "/local/dir/" [email protected]:"/remote/dir/"
But it's giving me an error:
Warning: Identity file ~/.ssh/1234-identity not accessible: No such file or directory.
The file is fine, permissions are set correctly, it works when doing ssh - just not with rsync - at least in my syntax. What am I doing wrong? Is it trying to look for the identity file on the remote machine? If so, how do I specify that I want to use an identity file on my local machine?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
使用
$HOME
或密钥的完整路径:
在 Ubuntu 上使用 rsync 3.0.9 进行测试
Use either
$HOME
or full path to the key:
Tested with rsync 3.0.9 on Ubuntu
您可能需要使用 ssh-agent 和 ssh-add 将密钥加载到内存中。如果 ssh-agent 可以找到它们,
ssh
将自动尝试来自 ssh-agent 的身份。命令是ssh-agent 是一个用户守护进程,它在内存中保存未加密的 ssh 密钥。 ssh 根据 ssh-agent 运行时输出的环境变量找到它。使用
eval
评估此输出会创建环境变量。ssh-add
是管理密钥内存的命令。可以使用 ssh-add 锁定代理。可以在启动 ssh-agent 时指定密钥的默认生存期,或者在添加密钥时指定密钥的默认生存期。您可能还想设置 ~/.ssh/config 文件来提供端口和密钥定义。 (有关更多选项,请参阅“man ssh_config”。)
单引号 ssh 命令将阻止
~
或$HOME
所需的 shell 扩展。您可以在单引号中使用键的完整路径或相对路径。You may want to use
ssh-agent
andssh-add
to load the key into memory.ssh
will try identities from ssh-agent automatically if it can find them. Commands would bessh-agent
is a user daemon which holds unencrypted ssh keys in memory. ssh finds it based on environment variables which ssh-agent outputs when run. Usingeval
to evaluate this output creates the environment variables.ssh-add
is the command which manages the keys memory. The agent can be locked using ssh-add. A default lifetime for a key can be specified when ssh-agent is started, and or specified for a key when it is added.You might also want to setup a ~/.ssh/config file to supply the port and key definition. (See `man ssh_config for more options.)
Single quoting the ssh command will prevent shell expansion which is needed for
~
or$HOME
. You could use the full or relative path to the key in single quotes.您必须指定身份密钥文件的绝对路径。这可能是Rsync中的某种Quirck。 (毕竟它不可能是完美的)
几天前我遇到了这个问题:-)
You have to specify the absolute path to your identity key file. This probably some sort of quirck in rsync. (it can't be perfect after all)
I ran into this issue just a few days ago :-)
这对我有用
This works for me
将密钥文件与 rsync 一起使用:
use key file with rsync:
你是在 bash 还是 sh 中执行命令?这可能会有所作为。尝试将
~
替换为$HOME
。尝试对-e
选项的字符串进行双引号。Are you executing the command in bash or sh? This might make a difference. Try replacing
~
with$HOME
. Try double-quoting the string for the-e
option.