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


10

在Ubuntu 12.10中,我使用lxc-create实用程序创建了类型为'ubuntu'的LXC。然后,我使用lxc-start-ephemeral实用程序基于该容器创建临时容器,并且需要使用无密码ssh连接到那些临时容器。但是,我需要保持其/ home / ubuntu文件夹的原始状态,因此不能在其中放置普通的.ssh / authorized_keys文件。

在“加密主目录”部分在这里告诉我如何移动的authorized_keys出来的home目录。从基本容器内部遵循这些说明后,无需输入密码就可以进入基本容器。

但是,当我从基本容器启动临时容器时,如果没有密码就无法进入。(令人困惑的是,当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

这是临时容器上/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)

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


更新:我认为问题可能是lxc-start-ephemeral使用的奇怪文件系统,所以我进行了一些更改。我首先阻止OVERLAY_DIR和EPHEMERAL_BIND_DIR成为tmpfs的目录,现在它们只是目录。那没有解决。然后,我将临时容器的根文件系统从overlayfs更改为简单的绑定安装。那确实解决了。不幸的是,这并不能解决我的问题,因为我需要overlayfs。
阿南德(2013年

Answers:


1

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

Authentication refused: bad ownership or modes for directory /

这是由于sshd服务对在其中找到authenticated_keys的目录具有严格的权限要求而引起的,不确定是否设法使根目录(/)大概与配置容器的方式有关。

如果您无法更改/的权限(在这种情况下可能会出现这种情况),则可以设置

StrictModes no

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

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.