netscrew.dev/playbooks/linux-cifs
Cross-Platform Networking

Linux CIFS / SMB Mounts & The Root Ownership Trap

Preventing 'Permission Denied' on Linux CIFS mounts caused by missing uid/gid options, and configuring secure /etc/fstab credentials files.

Read it offline, in your terminal:n -h linux-cifs

The Symptom

A Linux user mounts a Windows or Samba share using standard:

sudo mount -t cifs //192.168.1.76/data /mnt/data -o username=boss

The mount connects and files can be read. However, when the desktop user attempts to create a file, save a document, or run a script inside /mnt/data, Linux returns:

Permission Denied

The Root Cause: Default uid=0 Ownership

Because mount was executed with sudo, the Linux CIFS VFS driver assigns ownership of the entire mount to root:root with 0755 permissions unless explicit client mapping options are supplied.

Even if the remote Windows/Samba server authenticated you with Full Control, your local unprivileged Linux desktop account is treated as "Others" (Read-Only) by the Linux kernel!

The Remediation

Always specify your local Linux uid and gid, along with permissive file and directory modes:

sudo mount -t cifs //192.168.1.76/data /mnt/data \
  -o username=boss,uid=$(id -u),gid=$(id -g),file_mode=0775,dir_mode=0775

Permanent & Secure /etc/fstab Configuration

Never store passwords directly in /etc/fstab. Use an isolated credentials file:

1. Create /etc/samba/credentials:

username=boss
password=SecretPassword123!
domain=WORKGROUP

2. Lock down permissions so only root can read it:

sudo chmod 600 /etc/samba/credentials

3. Add to /etc/fstab:

//192.168.1.76/data /mnt/data cifs credentials=/etc/samba/credentials,uid=1000,gid=1000,file_mode=0775,dir_mode=0775,nofail 0 0

*(The nofail option ensures the Linux machine boots cleanly even if the network or NAS is powered off).*