【问题标题】:Can not access a file in a lxd container shared from the host无法访问与主机共享的 lxd 容器中的文件
【发布时间】:2019-03-23 20:06:11
【问题描述】:

我有一个lxd 容器,名为master。我发现它的根目录可以在:

/var/lib/lxd/containers/master/rootfs/home/ubuntu/

所以,我将我的文件夹 tars 转移到了这个地址。请注意,tars 有两个文件。

现在,我知道tars 的用户ID 和组ID 是root。另一方面,容器中所有其他文件的用户 ID 和组 ID 为 166536

因此,对于文件夹和文件,我使用sudo chown 166536 <file/folder name> 更改用户 ID,并使用sudo chown :166536 <file/folder name> 更改组 ID。

有一次,我这样做了,我希望 tars 可以从容器 master 访问,但这并没有发生。谁能告诉我我错过了什么?


这是一个方法,我在reddit上找到的:

是的,这就是答案,使用非特权容器运行你 无法查看 LXD 主机上的权限,因此显示为 无人:无人。在某种程度上很愚蠢,因为您可以将文件夹安装到 容器并查看其上的文件..

为了将来参考,对于遇到此问题的任何人,这是步骤 我做了(它可能不是正确的,但它有效)

sudo mkdir /tmp/share
adduser subsonic --shell=/bin/false --no-create-home --system --group --uid 6000 (this is a "service account")
sudo chown -R subsonic: /tmp/share
lxc exec Test -- /bin/bash
mkdir /mnt/share
adduser subsonic --shell=/bin/false --no-create-home --system --group --uid 6000 (important that the uid is the same)
exit
lxc stop Test
lxc config edit Test (add the line security.privileged: "true" right bellow config: save and exit)
lxc start Test
lxc config device add MyMusic MyLibrary disk source=/tmp/share path=/mnt/share
lxc exec Test -- /bin/bash
ls /mnt/share/ (note that the subsonic user is there)
exit

很遗憾,我找不到将用户映射到 非特权容器。如果有人知道,请告诉我。

基本上,为主机和容器创建一个普通用户。有没有比这种方法更好的方法?

【问题讨论】:

    标签: chown lxd


    【解决方案1】:

    当你打开容器并做时

    whoami
    

    你会得到结果:

    root
    

    所以,当前用户是root,而不是ubuntu。话虽如此,我将文件夹发送到的地址是错误的。当前地址是var/lib/lxd/containers/master/root/。发送文件夹后,检查 uid/gid(类似于 165536)。通过以下方式更改 uid:

    sudo chmod 165536 <folder-name>
    

    和gid:

    sudo chmod :165536 <folder-name>
    

    完成后,我们确信容器用户 root 将能够访问这些文件。

    或者一步到位sudo chmod 165536:165536 &lt;folder-name&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多