[英]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.