Mounting an SMB/CIFS Share Inside an Unprivileged LXC Container: kernel EACCES and the Host Bind-Mount Fix

Last Verified On: Kernel 6.8 / 6.12 LTS / Ubuntu 24.04 LTS & Debian 12/13 Safe (Read-Only) Exit Code: 13

Direct Answer / TL;DR

The kernel refuses CIFS mounts outside init_user_ns — cifs lacks FS_USERNS_MOUNT, so unprivileged LXC root (uid 0 mapped to 100000) mounts fail with error(13) EACCES. Fix: mount the share on the host with uid=/gid= matching uid_map, then bind it into the CT via lxc.mount.entry or pct mp0. Same recipe on Ubuntu 24.04, Debian 12, and RHEL 9.

mount -t cifs //10.0.0.5/data /mnt/cifs/data -o credentials=/root/.smbcred,uid=100000,gid=100000,vers=3.1.1
mount error(13): Permission denied Refer to the mount.cifs(8) manual page (e.g. man mount.cifs) and kernel log messages (dmesg)

Symptom & Exact Error Signature

Triggers when mount -t cifs (or an /etc/fstab CIFS line) is executed inside an unprivileged LXC, Proxmox CT, Incus container, or any container whose uid 0 is remapped — while the SMB server itself is reachable. The kernel rejects the mount at the VFS layer before a single SMB packet leaves the host, so dmesg on both sides stays empty.

root@webct:~# mount -t cifs //10.0.0.5/data /mnt/data -o credentials=/etc/cifs.cred,vers=3.1.1
mount error(13): Permission denied
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs) and kernel log messages (dmesg)

# Variant when LSM/seccomp blocks the syscall outright (e.g. Docker default seccomp profile):
mount error(1): Operation not permitted

Root Cause Breakdown

Three independent gates stack up, all evaluated before the SMB negotiation:

  1. VFS user-namespace gate (primary): the cifs file-system type does not set FS_USERNS_MOUNT. For types outside that allowlist, vfs_get_tree() demands CAP_SYS_ADMIN in init_user_ns — a capability an unprivileged container root does not hold, because caps are namespaced and uid 0 merely maps to host uid 100000 via uid_map. Result: errno 13 (EACCES) handed back to mount(2).
  2. LSM mediation: Ubuntu, Debian and Proxmox ship an AppArmor LXC profile that denies mount syscalls for foreign filesystem types inside user namespaces; Docker’s default seccomp profile rejects mount() entirely. These layers fail earlier with EPERM (errno 1).
  3. Helper expectations: mount.cifs assumes setuid-root invocation and its ioctl path wants CAP_NET_ADMIN. Adding lxc.cap.keep=sys_admin does not help: the capability is scoped to the container’s user_ns, never to init_user_ns.

Second-order trap: even when a host CIFS mount is bind-shared into the CT, the host-side uid=/gid= must match the container’s uid_map base (host_uid = base + ct_uid). Otherwise every object renders as nobody:nogroup (65534) and writes fail with EACCES despite a successful mount.

Step-by-Step Diagnostic & Fix Sequence

  1. Verify the state: confirm the uid shift inside the CT and a working host-side CIFS stack.
    # inside the CT — a shifted map proves unprivileged:
    $ cat /proc/1/uid_map
             0      100000      65536
    
    # on the host — module and helper must exist here:
    $ lsmod | grep ^cifs
    cifs                 1212416  0
    $ ls -l /sbin/mount.cifs
    -rwxr-xr-x 1 root root 44512 /sbin/mount.cifs

    mount error(19): No such device instead means the module is missing entirely — run modprobe cifs on the host. Expected diagnostic: shifted uid_map plus a functioning host mount stack.

  2. Apply the fix: mount on the host (with mapped uid/gid), then expose the mount to the CT.
    # (a) host credential file, mode 600:
    $ sudo tee /root/.smbcred >/dev/null <<'EOF'
    username=smbuser
    domain=WORKGROUP
    password=S3cret
    EOF
    $ sudo chmod 600 /root/.smbcred
    
    # (b) /etc/fstab — uid=100000/gid=100000 maps container root to share owner;
    #     for CT user 1000 use uid=101000 (base + ct_uid):
    //10.0.0.5/data  /mnt/cifs/data  cifs  credentials=/root/.smbcred,uid=100000,gid=100000,file_mode=0664,dir_mode=0775,iocharset=utf8,vers=3.1.1,_netdev,nofail  0  0
    
    $ sudo mkdir -p /mnt/cifs/data
    $ sudo mount /mnt/cifs/data
    # (c) generic LXC — append bind entry, destination is RELATIVE to CT root:
    $ echo 'lxc.mount.entry = /mnt/cifs/data mnt/cifs/data none bind,rslave,create=dir 0 0' |
        sudo tee -a /var/lib/lxc/<ctname>/config
    $ sudo lxc-stop -n <ctname> && sudo lxc-start -n <ctname>
    
    # (d) Proxmox VE — mp0 performs uid shifting automatically:
    $ pct set 110 -mp0 /mnt/cifs/data,mp=/mnt/data
    $ pct reboot 110
    # (e) Incus only: allow direct in-container CIFS mounts via syscall interception
    #     (the broker performs the real mount on the host):
    $ incus config set webct security.syscalls.intercept.mount=true 
          security.syscalls.intercept.mount.allowed=cifs
    $ incus restart webct
    
    # (f) rclone SMB over FUSE as kernel-free fallback (needs fuse device, Proxmox: pct set 110 -features fuse=1):
    $ rclone config create smbdata smb host=10.0.0.5 user=smbuser pass="$(rclone obscure 'S3cret')"
    $ rclone mount smbdata/data /mnt/data --allow-other --daemon
  3. Confirm resolution: from inside the CT, the mount must report cifs and be writable; both commands must exit 0.
    $ findmnt -no FSTYPE,SOURCE /mnt/data
    cifs    //10.0.0.5/data
    $ test -w /mnt/data && echo OK; echo $?
    OK
    0

    On the host, verify ownership mapping: stat -c '%u:%g' /mnt/cifs/data must print 100000:100000 (or your chosen mapped values).

Multi-Distro Command & Path Matrix

Ubuntu / Debian

sudo apt-get install -y cifs-utils
# Proxmox (Debian family) — id-shifting bind by VMID:
pct set 110 -mp0 /mnt/cifs/data,mp=/mnt/data
# generic LXC: /var/lib/lxc/<ctname>/config
#   lxc.mount.entry = /mnt/cifs/data mnt/cifs/data none bind,rslave,create=dir 0 0
# systemd automount variant (unit names escape dashes):
sudo systemctl start mnt-cifs\x2ddata.automount

RHEL / AlmaLinux / Rocky

sudo dnf -y install cifs-utils
# mount on host per fstab recipe, then bind; relabel flags (:Z) are
# unsupported on CIFS mounts — do not use them:
podman run -d --name web -v /mnt/cifs/data:/mnt/data docker.io/library/nginx
getsebool -a | grep container   # cifs_t access is governed by container-selinux policy

Arch Linux

sudo pacman -S --needed cifs-utils lxc
# /var/lib/lxc/<ctname>/config — same lxc.mount.entry line as Debian
sudo systemctl restart remote-fs.target   # apply fstab entries/automounts

Alpine / Containers

apk add cifs-utils rclone
# busybox mount -t cifs is host-only too; inside containers use bind or FUSE:
rclone mount :smb,host=10.0.0.5:user=smbuser:share /mnt/data --allow-other --daemon
# docker host-bind pattern (mount must exist on the docker host first):
docker run -d -v /mnt/cifs/data:/mnt/data nginx:alpine

Safety & Rollback Checks

Safety Check: Validate before applying and keep every step reversible:

# fstab syntax + existence validation (read-only):
sudo findmnt --verify --tab-file /etc/fstab
# fake mounting dry-run — reports what would happen, writes nothing:
sudo mount -fa -v
# backup the container config before editing:
sudo cp -a /var/lib/lxc/<ctname>/config /var/lib/lxc/<ctname>/config.$(date +%F).bak

Rollback: restore the config copy (or pct set 110 -delete mp0), remove the fstab line, run sudo umount /mnt/cifs/data, and lxc-start -n <ctname>. Keep nofail on every CIFS fstab entry — without it a dead SMB server blocks remote-fs.target at boot. Do not convert the CT to privileged merely to satisfy mount.cifs; host bind + interception preserves isolation. x-systemd.automount triggers (autofs) do not fire from inside user-namespace containers — bind only an already-active CIFS mount.

Frequently Asked Edge Cases

Can I mount CIFS directly inside an unprivileged LXC by granting SYS_ADMIN?

No. lxc.cap.keep=sys_admin only grants the capability inside the container's user namespace, while the cifs kernel gate checks CAP_SYS_ADMIN in init_user_ns; AppArmor on Ubuntu/Proxmox additionally denies the mount syscall. Use a host mount plus lxc.mount.entry, or Incus with security.syscalls.intercept.mount.allowed=cifs.

How do I map the share to a non-root container user, e.g. uid 1000?

Read the base from /proc/1/uid_map (e.g. 100000) and mount on the host with uid=$((base+ct_uid)) — uid=101000 for container uid 1000 — plus matching gid= and file_mode=0664,dir_mode=0775.

Why does x-systemd.automount stay dead after the bind-mount?

The bind exposes an autofs trigger, and autofs does not operate from inside user-namespace containers, so the trigger never fires in the CT. Keep the CIFS path as a plain nofail,_netdev host mount and bind the already-active cifs mount; reserve x-systemd.automount for host-only access.

References & Upstream Docs

  1. Linux man-pages: man 8 mount.cifs ; man 5 lxc.container.conf ; man 7 user_namespaces
  2. Kernel.org source tree: fs/smb/client — cifs is not FS_USERNS_MOUNT-flagged; gate enforced in vfs_get_tree() (fs/super.c)
  3. Linuxcontainers.org LXC documentation: lxc.mount.entry and mount propagation
  4. Incus documentation: security.syscalls.intercept.mount / .allowed / .shift keys

Related Concepts