如何将身份文件与rsync一起使用

如何将身份文件与rsync一起使用

本文介绍了如何将身份文件与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一起工作.我究竟做错了什么?是否正在尝试在远程计算机上查找身份文件?如果是这样,我如何指定要在我的 local 计算机上使用一个身份文件?

解决方案

您可能想使用ssh-agentssh-add将密钥加载到内存中.如果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扩展.您可以在单引号中使用键的完整或相对路径.

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?

解决方案

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.

这篇关于如何将身份文件与rsync一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-27 21:59