Linux

來自 OS X 客戶端的 ssh 連接問題

  • September 14, 2017

我正在嘗試建立從Travis CI提供的 OS X 盒子到 github.com 上的 git-over-ssh 的 ssh 連接。

沒什麼特別的:我的腳本採用 base64 編碼的無密碼私鑰,對其進行解碼並設置以下 git ssh 包裝器以強制使用密鑰:

unset SSH_AGENT_PID SSH_AUTH_SOCK

# Setting up bot key
echo "$BOT_SSH_KEY" | base64 --decode >$HOME/bot_id
chmod 600 $HOME/bot_id

# Setting up ssh wrapper
cat >$HOME/git-ssh <<__EOF__
#!/bin/sh -efx
ssh -vv -i "$HOME/bot_id" "\$@"
__EOF__
chmod a+x $HOME/git-ssh
export GIT_SSH="$HOME/git-ssh"

然後它嘗試執行 ssh-authenticated git clone,根據日誌,這會導致呼叫 ssh 客戶端。相同的腳本適用於 Travis 提供的 Ubuntu Linux 實例,但在 OS X 實例上失敗:

分析日誌,它們看起來非常相似,期望:

  • Ubuntu 使用 OpenSSH_6.6.1,OS X 使用 OpenSSH_6.9p1 => kex_parse_kexinit 列出了稍微不同的可用密碼集
  • Ubuntu 使用/home/travis/bot_id, OS X 使用/Users/travis/bot_id
  • OS X 發出額外的警告,因為無法看到密鑰的公共部分(可能不是什麼大問題):
debug1: key_load_public: No such file or directory
  • Ubuntu 成功後:
debug1: Server host key: RSA 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /home/travis/.ssh/known_hosts:2
Warning: Permanently added the RSA host key for IP address '192.30.253.112' to the list of known hosts.
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /home/travis/bot_id ((nil)), explicit
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/travis/bot_id
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type RSA
debug2: we sent a publickey packet, wait for reply
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([192.30.253.112]:22).
...
  • OS X 失敗:
debug1: Server host key: ssh-rsa SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8
debug1: read_passphrase: can't open /dev/tty: Device not configured
debug1: permanently_drop_suid: 501
ssh_askpass: exec(/usr/X11R6/bin/ssh-askpass): No such file or directory
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

據我了解,ssh 客戶端至少應該(1)連接,(2)驗證伺服器的密鑰和身份,(3)開始嘗試各種身份驗證方法。據我所見,OS X 獲得了連接,但隨後甚至不嘗試進行任何驗證(或抱怨 RSA 檢查失敗或其他),而是以某種方式繞過所有預設的身份驗證方法(即無密碼密鑰)並直接繼續“以互動方式詢問身份驗證資訊”方法=>然後失敗,因為它顯然已被禁用,因為 CI 不是互動式伺服器。

任何想法 OS X ssh 有什麼問題以及如何讓它工作,或者至少添加一些調試?正如我的猜測一樣,它可能以某種方式在伺服器的身份檢查中默默地失敗,但我不知道如何調試它(特別是考慮到我沒有任何方便的 OS X 盒子來互動式地嘗試它)。

事實證明,問題確實出在.ssh/known_hosts文件的內容上。Travis 的 ssh 使用了很多預設選項,因此它會嘗試對每個新密鑰進行確認,這反過來又會導致這個模糊的錯誤消息。

在 Ubuntu 上,Travis 團隊提供了一個預設.ssh/known_hosts文件,其中包含 5 行帶有流行 github 密鑰的行:

github.com,192.30.252.129 ssh-dss AAAAB3NzaC1kc3MAAACBANGFW2P9xlGU3zWrymJgI/lKo//ZW2WfVtmbsUZJ5uyKArtlQOT2+WRhcg4979aFxgKdcsqAYW3/LS1T2km3jYW/vr4Uzn+dXWODVk5VlUiZ1HFOHf6s6ITcZvjvdbp6ZbpM+DuJT7Bw+h5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G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==

但是,在 OS X 上,該文件不存在,這會觸發錯誤。這個最簡單的解決方案是在 OS X 上從 shell 腳本預先創建帶有這樣行的文件。

我已經向 Travis 團隊提出了這個問題。

引用自:https://unix.stackexchange.com/questions/392187