First we need to find the user ID of the container's user.
LXD might be installed in one of two ways. You can tell which, by running:
$ which lxc
/usr/bin/lxc # This means it's installed as a deb
# OR
/snap/bin/lxc # This means it's installed as a snap
If it's installed as a deb, the user IDs are likely 165536
and 166536
, and can be checked as follows:
$ ls -ld /var/lib/lxd/containers/caged-beaver/rootfs
drwxr-xr-x 22 165536 165536 4096 May 17 17:18 /var/lib/lxd/containers/caged-beaver/rootfs # The root user's ID is 165536
$ ls -ld /var/lib/lxd/containers/caged-beaver/rootfs/home/ubuntu
drwxr-xr-x 22 166536 166536 4096 May 17 17:18 /var/lib/lxd/containers/caged-beaver/rootfs/home/ubuntu # The ubuntu user's ID is 166536
Or, if LXD is installed as a snap, the IDs are likely 1000000
and 1001000
, and can be checked as follows:
$ sudo ls -ld /var/snap/lxd/common/mntns/var/snap/lxd/common/lxd/storage-pools/default/containers/caged-beaver/rootfs
drwxr-xr-x 22 1000000 1000000 22 Jan 31 15:51 /var/snap/lxd/common/mntns/var/snap/lxd/common/lxd/storage-pools/default/containers/caged-beaver/rootfs # The root user's ID is 1000000
$ sudo ls -ld /var/snap/lxd/common/mntns/var/snap/lxd/common/lxd/storage-pools/default/containers/caged-beaver/rootfs/home/ubuntu
drwxr-xr-x 3 1001000 1001000 6 Feb 5 14:04 /var/snap/lxd/common/mntns/var/snap/lxd/common/lxd/storage-pools/default/containers/caged-beaver/rootfs/home/ubuntu # The ubuntu user's ID is 1001000