如何通过 rsync 使用身份文件?

发布于 2024-10-29 18:45:38 字数 556 浏览 3 评论 0原文

如何通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

网名女生简单气质 2024-11-05 18:45:39

使用 $HOME

rsync -avz -e "ssh -p1234  -i \"$HOME/.ssh/1234-identity\"" dir remoteUser@server:

或密钥的完整路径:

rsync -avz -e "ssh -p1234  -i /home/username/.ssh/1234-identity" dir user@server:

在 Ubuntu 上使用 rsync 3.0.9 进行测试

Use either $HOME

rsync -avz -e "ssh -p1234  -i \"$HOME/.ssh/1234-identity\"" dir remoteUser@server:

or full path to the key:

rsync -avz -e "ssh -p1234  -i /home/username/.ssh/1234-identity" dir user@server:

Tested with rsync 3.0.9 on Ubuntu

心如荒岛 2024-11-05 18:45:39

您可能需要使用 ssh-agent 和 ssh-add 将密钥加载到内存中。如果 ssh-agent 可以找到它们,ssh 将自动尝试来自 ssh-agent 的身份。命令是

eval $(ssh-agent) # Create agent and environment variables
ssh-add ~/.ssh/1234-identity

ssh-agent 是一个用户守护进程,它在内存中保存未加密的 ssh 密钥。 ssh 根据 ssh-agent 运行时输出的环境变量找到它。使用 eval 评估此输出会创建环境变量。 ssh-add 是管理密钥内存的命令。可以使用 ssh-add 锁定代理。可以在启动 ssh-agent 时指定密钥的默认生存期,或者在添加密钥时指定密钥的默认生存期。

您可能还想设置 ~/.ssh/config 文件来提供端口和密钥定义。 (有关更多选项,请参阅“man ssh_config”。)

host 22.33.44.55
    IdentityFile ~/.ssh/1234-identity
    Port 1234

单引号 ssh 命令将阻止 ~$HOME 所需的 shell 扩展。您可以在单引号中使用键的完整路径或相对路径。

You may want to use ssh-agent and ssh-add to load the key into memory. ssh will try identities from ssh-agent automatically if it can find them. Commands would be

eval $(ssh-agent) # Create agent and environment variables
ssh-add ~/.ssh/1234-identity

ssh-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. Using eval 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.)

host 22.33.44.55
    IdentityFile ~/.ssh/1234-identity
    Port 1234

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.

情未る 2024-11-05 18:45:39

您必须指定身份密钥文件的绝对路径。这可能是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 :-)

梦年海沫深 2024-11-05 18:45:39

这对我有用

rsync -avz --rsh="ssh -p1234  -i ~/.ssh/1234-identity"  \
"/local/dir/" [email protected]:"/remote/dir/"

This works for me

rsync -avz --rsh="ssh -p1234  -i ~/.ssh/1234-identity"  \
"/local/dir/" [email protected]:"/remote/dir/"
白龙吟 2024-11-05 18:45:39

将密钥文件与 rsync 一起使用:

rsync -rave "ssh -i /home/test/pkey_new.pem" /var/www/test/ [email protected]:/var/www/test

use key file with rsync:

rsync -rave "ssh -i /home/test/pkey_new.pem" /var/www/test/ [email protected]:/var/www/test
箹锭⒈辈孓 2024-11-05 18:45:39

你是在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文