Sub topic 7
Mounting a Samba Share from Linux
Assume the Samba server already exports a share named projects, and the server hostname is fileserver. You also need a Samba account with permission to use that share. A Samba password is separate from the Linux login password unless the server uses a central identity system.
Install the client tools
The cifs-utils package provides the Linux mount helper for SMB shares. The smbclient command can inspect a server without mounting anything.
# Debian or Ubuntu
sudo apt install cifs-utils smbclient
# Fedora, RHEL, or another DNF-based system
sudo dnf install cifs-utils samba-clientList the shares offered by the server:
smbclient -L //fileserver -U aliceThe command prompts for Alice's Samba password. If this fails, check the hostname, network connection, account, and server permissions before attempting a mount.
Mount the share temporarily
Create a local directory to use as the mount point. A mount point is a directory where Linux attaches another filesystem.
sudo mkdir -p /mnt/projects
sudo mount -t cifs //fileserver/projects /mnt/projects \
-o username=alice,vers=3.0The mount command prompts for the password because it was not included in the command. -t cifs selects the Linux CIFS client, which supports SMB. vers=3.0 requests a modern SMB version. The server may support a different version, but avoid old protocols unless compatibility requires them.
After mounting, use the directory normally:
touch /mnt/projects/test.txt
ls -l /mnt/projects
sudo umount /mnt/projectsThe server still enforces its own share and filesystem permissions. Options such as uid and gid control which local user and group appear to own files on the client. They do not grant additional rights on the server.
Store credentials safely
For repeated mounts, put the password in a root-readable credentials file rather than in /etc/fstab or the process list.
sudo install -m 600 /dev/null /root/.smbcreds
sudo sh -c 'cat > /root/.smbcreds <<EOF
username=alice
password=REPLACE_WITH_SAMBA_PASSWORD
EOF'
sudo mount -t cifs //fileserver/projects /mnt/projects \
-o credentials=/root/.smbcreds,vers=3.0,uid=1000,gid=1000Replace 1000 with the intended local user and group IDs. Do not commit the credentials file to source control or make it readable by ordinary users.
Exercise
Why does changing the uid option not allow a user to bypass permissions on the Samba server?
Show answer
The uid option changes the ownership shown by the Linux client. Samba and the server filesystem still perform the authorization checks.