[英]Ansible with Github: Permission denied (Publickey)
我正在尝试用Ansible理解GitHub ssh配置(我正在研究Ansible:Up&Running书)。 我遇到了两个问题。
权限被拒绝(publickey) - 当我第一次运行ansible-playbook mezzanine.yml
playbook时,我得到了一个被拒绝的权限:
failed: [web] => {"cmd": "/usr/bin/git ls-remote '' -h refs/heads/HEAD", "failed": true, "rc": 128}
stderr: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
msg: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
FATAL: all hosts have already failed -- aborting
好吧,公平地说,我看到有几个人遇到过这个问题。 所以我跳到附录A用SSH运行Git,它说要运行ssh-agent并添加id_rsa公钥:
eval `ssh-agent -s`
ssh-add ~/.ssh/id_rsa
输出: Identity Added
我运行ssh-agent -l
来检查并得到长字符串: 2048 e3:fb:...
但是我得到了相同的输出。 所以我检查了关于ssh密钥生成和故障排除的Github文档,建议在我的主机上更新ssh配置文件:
Host github.com
User git
Port 22
Hostname github.com
IdentityFile ~/.ssh/id_rsa
TCPKeepAlive yes
IdentitiesOnly yes
但这仍然提供相同的错误。 所以在这一点上,我开始认为这是我的rsa文件,这导致了我的第二个问题。
密钥生成问题 - 我试图生成一个额外的证书,因为Github测试引发了另一个“Permission denied(publickey)”错误。
Warning: Permanently added the RSA host key for IP address '192.30.252.131' to the list of known hosts.
Permission denied (publickey).
我从头开始遵循Github指令并生成一个具有不同名称的新密钥。
ssh-keygen -t rsa -b 4096 -C "me@example.com"
我没有输入密码并将其保存到名为git_rsa.pub的.ssh文件夹中。 我运行了同样的测试,得到了以下内容:
$ ssh -i ~/.ssh/git_rsa.pub -T git@github.com
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/Users/antonioalaniz1/.ssh/git_rsa.pub' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: ~/.ssh/github_rsa.pub
Permission denied (publickey).
我检查了权限,并在文件上做了一个chmod 700
,我仍然得到Permission denied (publickey)
。 我甚至试图将密钥输入我的Github帐户,但首先得到一条消息,密钥文件需要以ssh-rsa
开头。 所以我开始研究和黑客攻击。 刚开始只输入文件中的长字符串(它以--BEGIN PRIVATE KEY--开头,但是在失败后我省略了那个部分); 然而,Github不接受它,说这是无效的。
这是我在YAML文件中的Ansible命令:
- name: check out the repository on the host
git: repo={{ repo_url }} dest={{ proj_path }} accept_hostkey=yes
vars:
repo_url: git@github.com:lorin/mezzanine-example.git
这是我配置了ForwardAgent的ansible.cfg文件:
[defaults]
hostfile = hosts
remote_user = vagrant
private_key_file = .vagrant/machines/default/virtualbox/private_key
host_key_checking = False
[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o ForwardAgent=yes
该框是使用Mac OS的Ubuntu Trusty64。 如果有人能够让我知道文件权限和/或Github密钥生成,我将不胜感激。
我有同样的问题,花了我一些时间,但我找到了解决方案。
问题是URL不正确。
只是尝试将其更改为:
repo_url: git://github.com/lorin/mezzanine-example.git
我怀疑关键权限问题是因为你传递公钥而不是私钥作为“ssh -i”的句子。 试试这个:
ssh -i ~/.ssh/git_rsa -T git@github.com
(注意它是git_rsa而不是git_rsa.pub)。
如果可行,请确保它在您的ssh-agent中。 加上:
ssh-add ~/.ssh/git_rsa
核实:
ssh-add -l
然后通过执行以下操作检查Ansible是否尊重代理转发:
ansible web -a "ssh-add -l"
最后,通过执行以下操作检查您是否可以通过ssh访问GitHub:
ansible web -a "ssh -T git@github.com"
你应该看到类似的东西:
web | FAILED | rc=1 >>
Hi lorin! You've successfully authenticated, but GitHub does not provide shell access.
我遇到了这个问题并通过在ansible命令上调整冗长来发现它(对调试非常有用)。
不幸的是,ssh经常会抛出错误消息,这些消息并不能引导您朝着正确的方向发展(同样被拒绝的权限是非常通用的......但是,如果存在文件权限问题,通常会被抛弃,因此可能不那么通用) 。 无论如何,运行带有详细信息的ansible test命令有助于重新创建问题并验证何时解决问题。
ansible -vvv all -a "ssh -T git@github.com"
同样,我使用的设置(以及典型的设置)是将ssh密钥加载到控制计算机上的代理程序中并启用转发。
它也向我伸出,当我通过vagrant命令ssh'd到盒子本身并运行测试时,它成功了。 所以我把它缩小到了ansible转发连接的方式。 对我来说最终奏效的是设定
[paramiko_connection]
record_host_keys = False
除了控制主机密钥的其他配置验证host_key_checking = False
这基本上增加了
-o StrictHostKeyChecking=no
为了你的ssh args,和
-o UserKnownHostsFile=/dev/null
也被添加到ssh args中
在这里找到: Ansible issue 9442
同样,这是关于流浪的虚拟机,应该在实际服务器上对主机密钥验证进行更仔细的考虑。
希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.