Linux CIFS Mount — Permission Error Fix
In this tutorial, you'll learn about Linux CIFS Mount. We cover key concepts, practical examples, and best practices.
CIFS mounts fail with "mount error(13): Permission denied", "mount error(95): Operation not supported", or mounted files appear owned by nobody and inaccessible. These happen when credentials are wrong, the SMB protocol version mismatches, or the uid/gid mapping is incorrect.
The Problem
sudo mount -t cifs //server/share /mnt -o username=user
Error:
mount error(13): Permission denied
Or the mount succeeds but:
ls -la /mnt
Shows:
drwxr-xr-x 2 nobody nogroup 0 Jun 24 10:30 .
Wrong Approach
# WRONG — no domain, no version, no uid mapping
sudo mount -t cifs //server/share /mnt -o username=user%password
Right Approach
sudo mount -t cifs //server/share /mnt \
-o username=user,password=pass,domain=WORKGROUP,vers=3.0,uid=$(id -u),gid=$(id -g),dir_mode=0755,file_mode=0644
Expected output:
$ ls -la /mnt
drwxr-xr-x 2 user user 4096 Jun 24 10:30 .
-rw-r--r-- 1 user user 123 Jun 24 10:30 file.txt
Step-by-Step Fix
Step 1: Use a credentials file instead of inline password
echo -e "username=user\npassword=mypass\ndomain=WORKGROUP" > ~/.smbcredentials
chmod 600 ~/.smbcredentials
Step 2: Mount with the correct protocol version
# SMB 3.0 for modern Windows (Server 2012+)
sudo mount -t cifs //server/share /mnt -o credentials=~/.smbcredentials,vers=3.0
# SMB 2.1 for older systems
sudo mount -t cifs //server/share /mnt -o credentials=~/.smbcredentials,vers=2.1
Step 3: Map UID and GID correctly
sudo mount -t cifs //server/share /mnt \
-o credentials=~/.smbcredentials,uid=1000,gid=1000
Step 4: Set file and directory permissions
sudo mount -t cifs //server/share /mnt \
-o credentials=~/.smbcredentials,uid=1000,gid=1000,dir_mode=0755,file_mode=0644,noperm
Step 5: Fix the fstab entry
//server/share /mnt cifs credentials=/home/user/.smbcredentials,vers=3.0,uid=1000,gid=1000,noperm,noexec 0 0
Step 6: Test the mount
mount -a
ls -la /mnt
touch /mnt/test && echo "Write works"
Prevention Tips
- Store credentials in a secure file (chmod 600) instead of inline
- Always specify
vers=3.0or higher for modern servers - Map uid/gid explicitly to your local user
- Use
nopermwhen the server handles permissions - Test with
mount -vfor verbose output during debugging
Common Mistakes with cifs mount
- Non-exhaustive pattern matches that compile with warnings then crash at runtime
- Misunderstanding that
Stringis[Char]with poor performance for large text operations - Using
foldlinstead offoldl'causing stack overflow on large lists
These mistakes appear frequently in real-world LINUX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro