Sub topic 7
Mounting a Samba share from Linux
This chapter covers the client side of Samba. It assumes you have a working share like the projects share from the earlier chapters, and that you know Linux users, groups, and permissions. You also need to be comfortable with sudo and basic networking. By the end you will be able to list shares, mount one with mount.cifs, control file ownership on the client, and read the common error messages.
The client-side model
A Linux client mounts an SMB share through the kernel CIFS client. The mount command hands the work to a helper called mount.cifs, which comes from the cifs-utils package. The helper resolves the server name, reads the credentials, and passes the options to the kernel. The kernel then speaks SMB to the server's smbd daemon.
Install the tools first:
# Debian and Ubuntu
sudo apt install cifs-utils smbclient
# RHEL, Fedora, Rocky, AlmaLinux
sudo dnf install cifs-utils samba-clientsmbclient is not needed for mounting. It is useful for checking what the server offers before you mount.
Listing shares before mounting
Ask the server what it offers:
smbclient -L //fileserver -U aliceYou are prompted for alice's Samba password. This is the password set with smbpasswd, not her Linux login password. The output lists share names, such as projects, and may include IPC$, which is a hidden share used for administration and share listing. If the share you expect is missing, check browseable and the share name in smb.conf.
A first mount
Create a mount point and mount the share:
sudo mkdir -p /mnt/projects
sudo mount -t cifs //fileserver/projects /mnt/projects -o username=alice,vers=3.0,uid=1000,gid=1000mount asks for the password. Check the result:
findmnt /mnt/projects
ls -l /mnt/projectsThe options in this command matter:
| Option | Meaning |
|---|---|
| `username=alice` | The Samba account to authenticate as. |
| `vers=3.0` | The SMB protocol version to request. Pinning it avoids silent fallback to older, weaker versions. |
| `uid=1000` | The local user ID that appears as owner of all files. |
| `gid=1000` | The local group ID that appears as group owner of all files. |
Ownership and permissions on the client
This is the most common point of confusion. A CIFS mount does not carry Linux owners from the server by default. The server enforces access based on who you logged in as, while the client shows every file as owned by whatever uid and gid you gave. Without those options, files appear as owned by root.
Two further options control the mode bits that the client displays:
file_mode=0664sets the permissions shown for files.dir_mode=0775sets the permissions shown for directories.
These options change only what the client displays. They do not grant access. If alice cannot write on the server because she is not in the staff group, no file_mode value will let her.
Use id to find the numbers for the local account:
id -u
id -gYou can also write uid=bob,gid=bob with names instead of numbers in recent versions of mount.cifs. Numbers are the safer choice in scripts.
When the server is configured with force group = staff and create mask = 0664, files created from the client appear on the server as owned by alice and the staff group, with group-write permission. This is why the server-side options from the share definition chapter matter: the client cannot override them.
Keeping the password out of the command line
Typing password=... into the mount command stores it in your shell history and exposes it in the process list. Use a credentials file instead.
sudo install -m 600 /dev/null /root/.smbcreds
sudo tee /root/.smbcreds >/dev/null <<'EOF'
username=alice
password=ChangeMeNow
domain=WORKGROUP
EOFThe install command creates an empty file readable only by root before the password is written. Mount with it:
sudo mount -t cifs //fileserver/projects /mnt/projects -o credentials=/root/.smbcreds,vers=3.0,uid=1000,gid=1000Choosing a protocol version
vers= selects the SMB dialect. The common values are:
| Value | Protocol | Notes |
|---|---|---|
| `vers=3.1.1` | SMB 3.1.1 | Newest. Supports pre-authentication integrity and AES-based encryption. |
| `vers=3.0` | SMB 3.0 | Widely supported. Supports encryption. |
| `vers=2.1` | SMB 2.1 | Acceptable for older servers. |
| `vers=1.0` | SMB 1 | Insecure and disabled in current kernels and servers. Avoid. |
The server example in this tutorial sets server min protocol = SMB2, so a client requesting vers=1.0 fails. That is the intended behavior. If you omit vers, the client negotiates the best common version, which is usually fine but makes the result depend on both sides' defaults.
To require encryption on the wire, add the seal option:
sudo mount -t cifs //fileserver/projects /mnt/projects -o credentials=/root/.smbcreds,vers=3.0,seal,uid=1000,gid=1000The mount fails if the server cannot encrypt, rather than falling back to plain text.
Making the mount permanent
An entry in /etc/fstab mounts the share at boot:
//fileserver/projects /mnt/smb-projects cifs credentials=/root/.smbcreds,vers=3.0,uid=1000,gid=1000,_netdev 0 0_netdev marks the filesystem as needing the network, so systemd waits for networking before it tries. Test an entry without rebooting:
sudo mount -a
findmnt /mnt/smb-projectsIf an unreachable server would stall boot, add nofail so a failed mount does not block startup. The full treatment of fstab options is in the persistent mounts chapter.
Common errors
| Message | Likely cause and fix |
|---|---|
| `mount error(13): Permission denied` | Wrong username or password, or the account has no Samba password. Run `smbpasswd -a` on the server. Also check `valid users`. |
| `mount error(2): No such file or directory` | The share name is wrong. Run `smbclient -L` and copy the name exactly. |
| `mount error(95): Operation not supported` or `mount error(112)` | Protocol version mismatch. Set `vers=` to a value both sides allow. |
| `mount error(115)` or `mount error(110)` | Connection timeout. Check the firewall and that `smbd` is running. |
| `mount: unknown filesystem type 'cifs'` | `cifs-utils` or the kernel module is missing. |
| Files owned by root, cannot write as a normal user | Add `uid=` and `gid=`, and check `file_mode` and `dir_mode`. |
When the message is unclear, read the kernel log, which often has a precise reason:
sudo dmesg | tail -n 20On the server, sudo smbstatus shows whether the connection arrived, and /var/log/samba/log.smbd records the reason for a refusal.
Unmounting
sudo umount /mnt/projectsIf you see target is busy, a process has a file open there. Find it with lsof +D /mnt/projects, or use sudo umount -l /mnt/projects for a lazy unmount that detaches the mount once it is no longer in use.
Exercise
You mount a share with -o username=alice,vers=3.0 and no uid or gid. A normal user can read files but cannot create any. What is the cause, and which options fix it?
Show answer
Without uid and gid, the client shows every file as owned by root, and the displayed mode bits give a normal user no write permission. Add uid= and gid= for the local user (and optionally file_mode=0664,dir_mode=0775). These options change only how the client displays ownership. The server must also allow alice to write, for example through membership in staff.
Exercise
Why is credentials=/root/.smbcreds better than password= in an fstab entry, and what file mode should the credentials file have?
Show answer
/etc/fstab is readable by every user, so a password= option exposes the password. A credentials file owned by root with mode 600 is readable only by root. Mode 600 is the required file mode.
Exercise
A mount with vers=1.0 fails against a server that has server min protocol = SMB2. Is that a bug? What would you change on the client?
Show answer
It is not a bug. The server refuses SMB1 by design. Change the client option to vers=3.0 (or 3.1.1 if both sides support it).