Ssh

通過終端的 SSH 成功,但通過 Ansible 的相同 SSH 連接在同一台機器上失敗?

  • July 19, 2014

任何人都可以解釋為什麼會這樣嗎?

我使用使用者 basicuser 登錄到客戶端機器 A。當我嘗試在機器 B(伺服器機器,作為遠端使用者)上執行 ansible playbook 時。

  • 1)我的私鑰/公鑰絕對匹配,正如在客戶端 A(作為基本使用者)上工作的“ssh user@serverB”所證明的那樣——ansible 和 SSH 都指向同一個私鑰
  • 2)我的 ~/.ssh/known_hosts 沒有過時
  • 3)我的 ~/.ssh 和 ~/.ssh/* 權限是正確的(分別由 basicuser 擁有,chmod 700
  • 4)我的 hosts.ini 文件包含所需的“ansible_ssh_user=remoteuser ansible_ssh_private_key_file=~/.ssh/id_rsa”(並且格式正確)

我知道 id_rsa 與 /home/remoteuser/.ssh 中機器 B 的“authorized_keys”文件中的唯一條目相匹配。

這是來自客戶端 A 通過終端的 SSH:

basicuser@serverA:~$ ssh remoteuser@serverB
Enter passphrase for key '/home/basicuser/.ssh/id_rsa':

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law.
Last login: Wed Jul 16 23:38:41 2014 from xxx.xxx.xxx.xxx
remoteuser@serverB:~$

這是我執行 ansible playbook 時會發生的情況:http: //pastebin.com/6wXgp3dd

我把它放在 pastebin 上,因為它的輸出相當多。然而,讓我感到奇怪的是接近尾聲的這一點:

debug2: key: /home/basicuser/.ssh/id_rsa ((nil))
debug1: Authentications that can continue: publickey
debug3: start over, passed a different list publickey
debug3: preferred gssapi-with-mic,gssapi-keyex,hostbased,publickey
debug3: authmethod_lookup publickey
debug3: remaining preferred: ,gssapi-keyex,hostbased,publickey
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/basicuser/.ssh/id_rsa
debug1: key_parse_private_pem: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
debug1: read PEM private key done: type RSA
debug3: sign_and_send_pubkey: RSA ed:bb:6d:4e:e3:7a:54:0a:19:f6:ee:1c:d0:f2:1b:3f
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey).

我現在已經花了大約三天的時間。為什麼終端 SSH 工作正常,但 ansible 卻失敗了?

我在 /etc/ssh/ssh_config 中沒有任何覆蓋 - 我需要任何覆蓋嗎?

經過多次調整和咖啡,我發現我做錯了什麼。我在我的 hosts.ini 和我的部署文件中複製了“ansible_ssh_user”參數 - 但不是私鑰參數。也就是說,我的 ssh 密鑰上沒有密碼!我不得不多次輸入片語 WAY。

謝謝各位大佬的見解

引用自:https://serverfault.com/questions/613222