Mount SMB CIFS Shares in Linux Using cifs-utils
This article provides an overview of how the Linux operating system
accesses Server Message Block (SMB) and Common Internet File System
(CIFS) network shares using the cifs-utils helper suite. It
examines the interaction between user-space utilities and the Linux
kernel, details the mounting process for both manual and automated
configurations, and explains how to manage authentication, file
permissions, and protocol versions securely.
The Architecture: User Space vs. Kernel Space
When Linux connects to a network share hosted on a Windows server, Samba server, or Network Attached Storage (NAS) device, it uses a hybrid mechanism split between the user space and the kernel:
- The Kernel Driver (
cifs.ko): The Linux kernel contains an in-tree virtual filesystem (VFS) client module responsible for network I/O, packet construction, caching, and SMB dialect negotiation (such as SMB 2.1, 3.0, and 3.1.1). - User-Space Helper (
cifs-utils): The standardmountcommand does not natively understand the full range of CIFS options or authentication mechanisms. Thecifs-utilspackage supplies the/sbin/mount.cifshelper binary. When a user runsmount -t cifs, the genericmountutility hands execution off tomount.cifs.
The mount.cifs helper parses user-specified parameters,
retrieves passwords, parses credentials files, and makes the system call
mount(2) with the appropriate binary data structure for the
kernel driver to establish the session.
Installing the Package
To enable SMB mounting capabilities, the cifs-utils
package must be installed via the distribution's package manager:
- Debian/Ubuntu:
sudo apt install cifs-utils - RHEL/CentOS/Fedora:
sudo dnf install cifs-utils - Arch Linux:
sudo pacman -S cifs-utils
How the Mount Process Works
When mounting a remote share, the connection sequence follows distinct stages:
- Invocation: The administrator issues a mount
command pointing to a UNC-style path using forward slashes (e.g.,
//server.domain.local/share). - Helper Execution:
/sbin/mount.cifsvalidates options, handles interactive password prompts if no password was supplied, and resolves the server hostname via DNS or NetBIOS/WINS. - Session Negotiation: The kernel's CIFS module initiates a TCP connection (typically over port 445) to negotiate the highest mutually supported SMB protocol dialect.
- Authentication: The client sends an authentication request (using NTLMv2 or Kerberos) to validate user credentials against the SMB server or Active Directory domain.
- VFS Attachment: Upon successful validation, the remote tree connect is completed, and the CIFS client maps the remote root directory onto the local target mount point in the Linux VFS.
Mounting an SMB Share Manually
A basic manual mount command requires root privileges, the remote path, the local mount directory, and user authentication options:
sudo mount -t cifs //192.168.1.50/data /mnt/nas -o username=smbuser,vers=3.1.1If the password is not provided in the command line,
mount.cifs pauses execution and prompts for it securely via
the terminal. The vers= option specifies the SMB dialect,
where vers=3.0 or vers=3.1.1 ensures modern
security and performance.
Handling Linux Permissions and Ownership
Because SMB is primarily a Windows-native protocol, traditional SMB shares do not always store native POSIX file modes, owners, or groups. Linux compensates for this during the mount operation by virtualizing metadata on the client side using mount options:
uid: Assigns local ownership of all files on the share to a specific local user ID or name (e.g.,uid=1000).gid: Assigns group ownership to a local group ID or name (e.g.,gid=1000).file_mode: Overrides default permissions for files (e.g.,file_mode=0664).dir_mode: Overrides default permissions for directories (e.g.,dir_mode=0775).
Example command setting local ownership and permissions:
sudo mount -t cifs //192.168.1.50/data /mnt/nas -o username=smbuser,uid=1000,gid=1000,file_mode=0660,dir_mode=0770Persistent Mounts with /etc/fstab
To mount an SMB share automatically at boot, the configuration must
be added to /etc/fstab.
Storing Credentials Securely
Storing credentials directly inside /etc/fstab is
insecure because the file is world-readable. Instead, store the
credentials in an isolated file:
Create /etc/samba/credentials:
username=smbuser
password=ComplexPassword123
domain=WORKGROUPRestrict file permissions so only root can view the
file:
sudo chmod 600 /etc/samba/credentialsThe /etc/fstab Entry
Add the mount definition to /etc/fstab:
//192.168.1.50/data /mnt/nas cifs credentials=/etc/samba/credentials,uid=1000,gid=1000,_netdev,nofail,vers=3.1.1 0 0
_netdev: Informs the system that this mount requires an active network interface, delaying mounting until network services are online.nofail: Prevents the operating system from halting the boot process if the network share is unavailable.