Docker 中非 root 用户的无密码 ssh

Docker 中非 root 用户的无密码 ssh

在为非 root 用户在 docker 节点之间设置无密码 SSH 时,我遇到了一个从未见过的奇怪问题。为了做好准备,以下是有效的方法:对于节点 1 上的 root 用户:

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

我现在可以从 node1 到 node2 进行 ssh,无需密码。

我使用不同的用户(即 mark)。我执行上述相同的步骤,生成密钥并复制到 node2,仍然得到提示。我打开诊断程序(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...(或无论哪种方式)看看它是否允许您使用 mark 的密钥以及这样做是否有效。作为测试,尝试重命名 root 的密钥,看看它会做什么!

另外,(忘记 -i)查看是否存在文件 ~/.ssh/config,如果存在,则查看其中是否有任何内容。并查看IdentityFile ____/etc/ssh_config 中是否有一行可能指定 root 的密钥。

相关内容