Docker 中非 root 使用者的無密碼 ssh

Docker 中非 root 使用者的無密碼 ssh

在為非 root 使用者設定 docker 節點之間的無密碼 SSH 時,我遇到了一個以前從未見過的奇怪問題。為了做好準備,以下是有效的方法: 對於節點 1 上的 root 使用者:

ssh-keygen -t rsa ...
ssh-copy-id node2

我現在可以從節點 1 -> 節點 2 進行 ssh,無需密碼。

我使用不同的使用者(即標記)。我執行上面相同的步驟,產生金鑰並複製到節點2,但仍然收到提示。我打開診斷(ssh -v node2)並得到以下資訊:

[mark@node1 ~]$ ssh -v node2
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to node2 [172.17.0.3] port 22.
debug1: Connection established.
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_rsa-cert type -1
... more stuff
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Next authentication method: password
...

我覺得很奇怪,除了這裡的另一篇文章(https://stackoverflow.com/questions/18136389/using-ssh-keys-inside-docker-container)其中一位發文者發表了以下評論:“請記住,docker 使用 sudo 運行(除非您不這樣做),如果是這種情況,您將使用 root ssh 密鑰。”這引起了我的注意,因為我懷疑這可能是我問題的本質。

由於我無法在那裡發布後續問題,因此我想我應該在這裡重新建置問題。我在 Docker 文件中找不到任何關於此問題的詳細信息,但它似乎確實影響了非 root 用戶的無密碼 ssh 的行為。

我很感激任何人都能提供的清晰資訊。

答案1

為了排除故障/了解發生的情況,值得嘗試ssh -i /home/mark/.ssh/id_rsa...(或無論它是什麼路徑)看看它是否允許您使用標記的密鑰以及這樣做時它是否有效。作為測試,嘗試重命名 root 的金鑰,看看它會做什麼!

另外,(忘記 -i)看看是否有檔案 ~/.ssh/config 如果有的話,裡面有東西。並查看 /etc/ssh_config 中是否有一行IdentityFile ____可能指定 root 的金鑰。

相關內容