Linux 容器可以使用我的主目录之外的 authorized_keys 文件,但基于它的临时容器不能。为什么?

Ana*_*and 10 ssh filesystem lxc

在 Ubuntu 12.10 中,我使用 lxc-create 实用程序创建了一个“ubuntu”类型的 LXC。然后,我使用 lxc-start-ephemeral 实用程序基于此容器创建临时容器,并且我需要使用无密码 ssh 连接到那些容器。但是,我需要保持他们的 /home/ubuntu 文件夹原始,所以我不能把通常的 .ssh/authorized_keys 文件放在那里。

在“加密主目录”部分在这里告诉我如何移动的authorized_keys出来的home目录。在我按照基本容器内部的这些说明进行操作后,我可以在不提供密码的情况下通过 ssh 进入基本容器。

但是,当我从基础容器启动临时容器时,没有密码就无法 ssh 进入。(令人困惑的是,当authorized_keys 位于/home/ubuntu/.ssh 中的通常位置时,临时容器的无密码ssh确实有效。)我该如何解决这个问题?

这是 ssh -v 所说的,从它接受主机密钥开始:

debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/ubuntu/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/ubuntu/.ssh/id_dsa
debug1: Trying private key: /home/ubuntu/.ssh/id_ecdsa
debug1: Next authentication method: password
Run Code Online (Sandbox Code Playgroud)

以下是临时容器上 /var/log/auth.log 的相关部分:

Apr 11 00:06:52 test-temp-SNeWevO sshd[306]: Authentication refused: bad ownership or modes for directory /
Apr 11 00:06:54 test-temp-SNeWevO sshd[306]: Accepted password for ubuntu from 10.0.3.1 port 59677 ssh2
Apr 11 00:06:54 test-temp-SNeWevO sshd[306]: pam_env(sshd:setcred): Unable to open env file: /etc/default/locale: No such file or directory
Apr 11 00:06:54 test-temp-SNeWevO sshd[306]: pam_unix(sshd:session): session opened for user ubuntu by (uid=0)
Run Code Online (Sandbox Code Playgroud)

我在基于标准 Ubuntu 12.10 AMI 的全新 AWS 微型实例上进行了此测试,如果有帮助,我可以提供有关如何重现它的详细说明。

tek*_*aul 1

这是一个老问题,但它仍然出现在谷歌......

Authentication refused: bad ownership or modes for directory /
Run Code Online (Sandbox Code Playgroud)

是由于 sshd 服务对authorized_keys所在的目录有严格的权限要求引起的,不确定您如何设法使根目录(/)可能与配置容器的方式有关。

如果您无法更改 / 的权限(在这种情况下似乎很可能),您可以设置

StrictModes no
Run Code Online (Sandbox Code Playgroud)

在 sshd_config.php 中
如果没有多个用户访问服务器,那么这样做对安全性影响很小。