将服务器添加到known_hosts

我想从命令行中将github.com添加到known_hosts文件中,因为我创build了一个puppet清单来configuration远程服务器。

我努力了:

"ssh-keyscan -H github.com > /home/ubuntu/.ssh/known_hosts" 

但是当服务器试图访问github时:

 Failed to add the RSA host key for IP address '207.97.227.239' to the list of known hosts (/home/ubuntu/.ssh/known_hosts). 

我也试过:

 "ssh-keyscan -H github.com,207.97.227.239 > /home/ubuntu/.ssh/known_hosts"` 

但访问github抛出:

 Host key verification failed. 

我敢肯定,这是没有额外的用途,但如果我ssh我的服务器,然后ssh github,并按照步骤,我收到以下消息Permanently added 'github.com,207.97.227.239' (RSA) to the list of known hosts那么它会完美的工作。

谢谢

我们通过在puppet服务器上放置known_hosts文件并直接从puppet提供文件来处理这个问题:

 file{ "/home/appuser/.ssh/known_hosts": owner => "appuser", group => "appuser", mode => 755, source => "puppet:///modules/ssh/known_hosts", require => File["/home/appuser"]; } 

这将从puppet仓库复制格式正确的known_hosts文件,相应地设置用户,并确保它具有正确的权限。 适合我们。

这是在接受的答案的评论中提到的,但我碰到这个,并认为这个更干净的解决scheme值得自己的答案。

Puppet的核心sshkeytypes将密钥安装到整个服务器范围内的/ etc / ssh / ssh_known_hosts文件中,而不必重新打开整个文件。 对于这种情况:

 sshkey {'github': name => 'github.com', ensure => present, key => '[GitHub key (just the part after ssh-rsa, starting with AAA)]', type => 'ssh-rsa', } 

将很好地安装它。