与Github Ansible:权限被拒绝(公钥)

三明治热

我正在尝试使用Ansible了解GitHub的ssh配置(我正在编写Ansible:启动和运行书)。我遇到两个问题。

权限被拒绝(公钥) -首次运行ansible-playbook mezzanine.yml剧本时,我被拒绝了权限:

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测试引发了另一个“权限被拒绝(公钥)”错误。

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 "[email protected]"

我没有输入密码并将其保存到名称为git_rsa.pub的.ssh文件夹中。我进行了相同的测试,并得到以下结果:

$ ssh -i ~/.ssh/git_rsa.pub -T [email protected]
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         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: [email protected]: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密钥生成,我将不胜感激。

洛林·霍希斯坦(Lorin Hochstein)

我怀疑密钥许可问题是因为您将公钥而不是私钥作为“ ssh -i”的缩写。尝试以下方法:

ssh -i ~/.ssh/git_rsa -T [email protected]

(请注意,它是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 [email protected]"

您应该看到类似以下内容:

web | FAILED | rc=1 >>
Hi lorin! You've successfully authenticated, but GitHub does not provide shell access.

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Ansible git clone github 权限被拒绝(公钥)

Bitbucket / Github:权限被拒绝的公钥

GitHub错误消息-权限被拒绝(公钥)

Github SSH访问:权限被拒绝(公钥)

[email protected]:权限被拒绝(公钥)

Maven发布插件:权限被拒绝(公钥)Github

GitHub:权限被拒绝(公钥)。致命:远端意外挂断

无法通过ssh连接到github;权限被拒绝(公钥)

不能推Vue的CLI应用github.io生成后 - 权限被拒绝(公钥)

尽管在代理中添加了身份,但仍无法使用SourceTree推送到github:权限被拒绝(公钥)

使用ssh从github部署到linux服务器,但是权限被拒绝(公钥)。PHP脚本

GitHub:权限被拒绝(公钥)。严重的:无法从远程存储库读取

为什么[email protected]:Windows中的权限被拒绝(公钥)?

Github:权限被拒绝(公钥),但是我收到“您已成功通过身份验证”消息

通过Github Actions CI / CD访问服务器时,Git权限被拒绝(公钥)

每次重新打开git bash:[email protected]:权限被拒绝(公钥)

[email protected]:进行酒桶安装“程序”时,权限被拒绝(公钥)

Ansible git权限被拒绝(公钥)

Ansible:权限被拒绝(公钥,密码)

从xero-python-oauth2-starter-master安装依赖项时出现“ [email protected]:权限被拒绝(公钥)”

[email protected]:权限被拒绝(公钥)。致命:无法从远程存储库读取。在云9上

Git 子模块:[email protected]:权限被拒绝(公钥)。致命:无法从远程存储库读取

权限被拒绝(公钥)

通过公钥授予对 GitHub 中不同存储库的权限

SSH错误:Ansible中的权限被拒绝(公钥,密码)

Ansible remote_user:root,ssh:权限被拒绝(公钥)

为什么git push只能用于一个仓库,而不能用于另一个仓库?[email protected]:权限被拒绝(公钥)

SSH权限被拒绝(公钥)

git权限被拒绝(公钥)