bash rsyncing 时如何自动接受远程密钥?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18123554/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to automatically accept the remote key when rsyncing?
提问by Bravo Delta
I'm attempting to make a system which automatically copies files from one server to many servers. As part of that I'm using rsync and installing SSH keys, which works correctly.
我正在尝试制作一个自动将文件从一台服务器复制到多台服务器的系统。作为其中的一部分,我正在使用 rsync 并安装 SSH 密钥,它可以正常工作。
My problem is that when it attempts to connect to a new server for the first time it will ask for a confirmation. Is there a way to automatically accept?
我的问题是,当它第一次尝试连接到新服务器时,它会要求确认。有没有办法自动接受?
Example command/output:
示例命令/输出:
rsync -v -e ssh * root@someip:/data/
The authenticity of host 'someip (someip)' can't be established.
RSA key fingerprint is somerandomrsakey.
Are you sure you want to continue connecting (yes/no)? yes
回答by Yorik.sar
You can add this host's key to known_hosts beforehand like this:
您可以像这样预先将此主机的密钥添加到 known_hosts:
ssh-keyscan $someip >> ~/.ssh/known_hosts
回答by Brian Agnew
If they genuinely arenew hosts, and you can't add the keys to known_hosts
beforehand (see York.Sar's answer), then you can use this option:
如果他们确实是新主机,并且您无法known_hosts
预先添加密钥(请参阅 York.Sar 的回答),那么您可以使用此选项:
-e "ssh -o StrictHostKeyChecking=no"
回答by Iwnnay
I know that this was asked 3 years ago, but this was at the top of my google search and I was unable to get either of these solutions in the middle of a Vagrant script to work correctly for me. So I wanted to put here the method that I found somewhere else.
我知道这是 3 年前提出的问题,但这是我谷歌搜索的顶部,我无法在 Vagrant 脚本中间获得这些解决方案中的任何一个来为我正常工作。所以我想把我在别处找到的方法放在这里。
The solution there talks about updating the ~/.ssh/config
or /etc/ssh/ssh_config
file with the following blocks of code.
那里的解决方案讨论了使用以下代码块更新~/.ssh/config
或/etc/ssh/ssh_config
文件。
To disable host key checking for a particular host (e.g., remote_host.com):
要禁用特定主机的主机密钥检查(例如,remote_host.com):
Host remote_host.com
StrictHostKeyChecking no
To turn off host key checking for all hosts you connect to:
要关闭对您连接到的所有主机的主机密钥检查:
Host *
StrictHostKeyChecking no
To avoid host key verification, and not use known_hosts file for 192.168.1.* subnet:
为避免主机密钥验证,并且不为 192.168.1.* 子网使用 known_hosts 文件:
Host 192.168.0.*
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
I hope this helps someone else who runs into this issue.
我希望这可以帮助遇到此问题的其他人。