Linux talks to SMB (the protocol behind Windows file shares and Samba) via the cifs.ko kernel module and the mount.cifs userspace helper from cifs-utils. Mounting a share is one command — but the parts that hurt in practice are credentials handling (don’t put passwords on the command line), SMB protocol version negotiation (SMB1 is dangerous, modern servers want SMB3), and the UID/GID mapping that determines what files appear to be owned by on the Linux side. This article walks the install, the credentials file pattern we use, and the version-pinning options that prevent the silent fall-back to insecure protocols.
How to verify
# Package and kernel module
apt list --installed cifs-utils 2>/dev/null
modinfo cifs | head -5
sudo modprobe cifs
lsmod | grep cifs
# After mount
mount | grep cifs
sudo smbstatus # only on the Samba server side
findmnt /mnt/share
df -h /mnt/share
# Diagnostic
dmesg | grep CIFS | tail -20
sudo smbclient -L //server -U username
What’s happening
The SMB protocol family has several major versions. SMB1 (also called CIFS) dates from the 1990s and has known security issues — it’s enabled by default on some old appliances and disabled everywhere modern. SMB2 introduced major improvements; SMB3 added encryption, signing, and multichannel. Modern Linux clients negotiate up to the highest version the server supports, but you should explicitly pin with vers=3.0 or vers=3.1.1 to avoid the silent fall-back to SMB1 that older defaults allowed.
The credentials problem: mount.cifs accepts -o username=...,password=... but every shell user on the system can read that mount’s options via /proc/mounts. The right pattern is a credentials file with chmod 600 containing username, password, and (optionally) domain, referenced via credentials=/path/to/file. That file should be outside any shared home directory.
UID/GID mapping: SMB doesn’t carry Linux-style POSIX ownership in most modes, so when you mount a share, every file looks like it’s owned by whoever you specify in the mount options (default: the user who issued mount). The uid=, gid=, file_mode=, dir_mode= options control what the mount presents. There’s a separate mode called Unix Extensions (or SMB3 POSIX) that does carry POSIX ownership when both ends agree, but it’s not universal.
The multiuser mount option is the production-grade feature: one mount can serve multiple Linux users, each using their own SMB credentials via per-user PAM credentials. This is essential when a multi-user server needs to write to a corporate file share as different identities — without it, every file shows the same owner.
The procedure
-
Install the userspace tooling:
sudo apt update sudo apt install -y cifs-utils -
Create a credentials file (outside any synced/backed-up location, owned by root):
sudo install -d -m 0700 /etc/samba/credentials sudo install -m 0600 /dev/null /etc/samba/credentials/fileserver # Then edit:Contents:
username=svc-fileserver password=<strong-secret> domain=CORP -
Create the mount point and do an ad-hoc mount to verify connectivity:
sudo mkdir -p /mnt/fileserver sudo mount -t cifs //fileserver.corp.example/shared /mnt/fileserver \ -o credentials=/etc/samba/credentials/fileserver,vers=3.0,uid=1000,gid=1000,file_mode=0664,dir_mode=0775,iocharset=utf8 ls /mnt/fileserver -
Persist via
/etc/fstab(note_netdevandnofailso a missing server doesn’t block boot)://fileserver.corp.example/shared /mnt/fileserver cifs credentials=/etc/samba/credentials/fileserver,vers=3.0,uid=1000,gid=1000,file_mode=0664,dir_mode=0775,iocharset=utf8,_netdev,nofail 0 0 -
For multi-user mounts (one mount, multiple Linux users each with their own SMB credentials):
sudo mount -t cifs //fileserver.corp.example/shared /mnt/fileserver \ -o credentials=/etc/samba/credentials/fileserver,vers=3.0,multiuser,sec=krb5Each user then runs:
cifscreds add fileserver.corp.example -
Test SMB3 encryption (if the server supports it):
sudo mount -t cifs //fileserver.corp.example/shared /mnt/fileserver \ -o credentials=/etc/samba/credentials/fileserver,vers=3.1.1,seal mount | grep fileserver | grep seal -
Unmount cleanly:
sudo umount /mnt/fileserver # If it hangs (server unreachable): sudo umount -l /mnt/fileserver
Common pitfalls
- Not pinning
vers=causes the kernel to negotiate down to SMB1 against some old servers, which silently disables modern security. Always pin. - Credentials file permissions left at 0644 are world-readable — every user can grab the password.
chmod 600andchown root:rootit. - The default
uid=/gid=is whoever ranmount, so amountinvoked by root makes everything owned by root, regardless of which user is using the share. Explicituid=is almost always what you want. dmesg | grep CIFSis the first place to look when something goes wrong — kernel-side mount errors don’t surface to userspace beyond a generic failure.- Filename case sensitivity: SMB is case-insensitive by default, ext4 is case-sensitive — a file
Report.txton the server may also appear asreport.txtto applications looking for either, and writing to one updates both. Usenocaseormfsymlinksif you need specific semantics.
In the engagements we run, SMB mounts on Linux show up when a customer’s environment includes a Windows file server that an application server needs to read from or write to — typically migration scenarios or legacy integrations. We pin SMB3, use credentials files with strict permissions, and document the UID mapping so file ownership matches what the application expects. For greenfield Linux-to-Linux file sharing, NFSv4 is the better default; we use SMB when the Windows server is the unmovable constraint.