Skip to content

Instantly share code, notes, and snippets.

@nottrobin
Created February 5, 2019 15:02
Show Gist options
  • Save nottrobin/032c7907c506f99e5fb31255f2f6ff2a to your computer and use it in GitHub Desktop.
Save nottrobin/032c7907c506f99e5fb31255f2f6ff2a to your computer and use it in GitHub Desktop.
Find the user IDs of LXC containers, for either Snap or Deb installs

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment