Top Tags

How to Mount Samba Share on Ubuntu using CIFS Protocol - Complete Guide

Learn how to mount Samba/SMB network shares on Ubuntu using CIFS protocol. Step-by-step guide with permanent mounting, security options, and troubleshooting tips for Linux system administrators.

Mount Samba Share on Ubuntu using CIFS Protocol

This guide demonstrates how to mount Samba (SMB/CIFS) network shares on Ubuntu Linux systems. CIFS (Common Internet File System) is the standard protocol for accessing Windows file shares and Samba servers from Linux.

Understanding CIFS and Samba

CIFS (Common Internet File System) is a network file-sharing protocol based on SMB (Server Message Block). It allows Linux systems to mount remote Windows or Samba shares as if they were local directories. The cifs-utils package provides the necessary tools for mounting CIFS shares on Linux.

Prerequisites

Before mounting Samba shares, ensure the CIFS utilities are installed:

bash
1sudo apt update
2sudo apt install cifs-utils

Basic Temporary Mount

To mount a Samba share temporarily (until reboot), create a mount point and use the mount command:

bash
1mkdir /mnt/samba
2sudo mount -t cifs //192.168.0.5/sataDrive /mnt/samba -o username=usr,password=123

Command breakdown:

  • -t cifs - Specifies the filesystem type as CIFS
  • //192.168.0.5/sataDrive - The remote share path (server IP/hostname and share name)
  • /mnt/samba - Local mount point directory
  • -o username=usr,password=123 - Mount options for authentication

Secure Credentials Management

For better security, avoid storing passwords in plain text. Use a credentials file instead:

bash
1# Create a secure credentials file
2sudo nano /etc/samba/credentials
3
4# Add your credentials:
5username=usr
6password=123
7domain=WORKGROUP
bash
1# Secure the credentials file (readable only by root)
2sudo chmod 600 /etc/samba/credentials
3sudo chown root:root /etc/samba/credentials
bash
1# Mount using the credentials file
2sudo mount -t cifs //192.168.0.5/sataDrive /mnt/samba -o credentials=/etc/samba/credentials,uid=1000,gid=1000

Permanent Mount Configuration

To automatically mount the Samba share at boot, add an entry to /etc/fstab:

bash
1sudo nano /etc/fstab
2//192.168.0.5/sataDrive /mnt/samba cifs username=usr,password=123,uid=1000,gid=1000,rw,iocharset=utf8,vers=3.0 0 0

Understanding fstab Mount Options

OptionDescription
uid=1000Sets the owner UID (use id -u to find yours)
gid=1000Sets the owner GID (use id -g to find yours)
rwMount as read-write (use ro for read-only)
iocharset=utf8Character encoding for file names
vers=3.0SMB protocol version (2.0, 2.1, 3.0, 3.1.1)
0 0Dump and fsck options (always 0 for network shares)

Recommended fstab Entry with Credentials File

For improved security and reliability, use this enhanced configuration:

bash
1# Using credentials file (recommended)
2//192.168.0.5/sataDrive /mnt/samba cifs credentials=/etc/samba/credentials,uid=1000,gid=1000,file_mode=0755,dir_mode=0755,vers=3.0,_netdev,x-systemd.automount 0 0

Additional options explained:

  • file_mode=0755 - Permission mode for files (rwxr-xr-x)
  • dir_mode=0755 - Permission mode for directories
  • _netdev - Wait for network to be available before mounting
  • x-systemd.automount - Mount automatically when accessed (on-demand)
  • nofail - Continue boot even if mount fails (add if optional)

Apply fstab Changes

After editing /etc/fstab, test your configuration:

bash
1# Test mount all entries in fstab
2sudo mount -a
3
4# Verify the mount
5df -h | grep samba
6mount | grep samba
7
8# Check if files are accessible
9ls -la /mnt/samba

Advanced Mount Options

Guest Access (No Authentication)

bash
1# Temporary guest mount
2sudo mount -t cifs //192.168.0.5/public /mnt/public -o guest,uid=1000,gid=1000
3
4# fstab entry for guest access
5//192.168.0.5/public /mnt/public cifs guest,uid=1000,gid=1000,_netdev 0 0

Domain Authentication

bash
1# Mount with domain credentials
2sudo mount -t cifs //server.domain.com/share /mnt/domain -o username=user,password=pass,domain=DOMAIN
3
4# fstab with domain
5//server.domain.com/share /mnt/domain cifs credentials=/etc/samba/domain-creds,domain=DOMAIN,uid=1000,gid=1000 0 0

Performance Tuning Options

bash
1# High-performance mount options
2//192.168.0.5/sataDrive /mnt/samba cifs credentials=/etc/samba/credentials,uid=1000,gid=1000,vers=3.1.1,cache=loose,actimeo=30 0 0

Performance options:

  • cache=loose - More aggressive caching for better performance
  • cache=strict - Strict cache coherency (safer but slower)
  • cache=none - Disable caching (not recommended)
  • actimeo=30 - Attribute cache timeout in seconds

Troubleshooting

Check CIFS Version Support

bash
1# List available SMB protocol versions
2sudo modinfo cifs | grep version
3
4# Test connection with specific version
5sudo mount -t cifs //192.168.0.5/share /mnt/test -o username=usr,password=123,vers=2.1

Debug Mount Issues

bash
1# Enable verbose output for debugging
2sudo mount -t cifs //192.168.0.5/share /mnt/samba -o username=usr,password=123,vers=3.0 -vvv
3
4# Check system logs for errors
5sudo dmesg | grep CIFS
6sudo journalctl -u systemd-networkd -f

Common Error Solutions

Error: "mount error(13): Permission denied"

bash
1# Verify credentials and share permissions
2smbclient -L //192.168.0.5 -U usr
3
4# Try different protocol version
5sudo mount -t cifs //192.168.0.5/share /mnt/samba -o username=usr,password=123,vers=1.0

Error: "mount error(2): No such file or directory"

bash
1# Check if server is reachable
2ping 192.168.0.5
3
4# Verify share name
5smbclient -L //192.168.0.5 -U usr -N

Error: "Host is down"

bash
1# Install and use smbclient for testing
2sudo apt install smbclient
3smbclient //192.168.0.5/sataDrive -U usr

Unmounting Samba Shares

bash
1# Unmount a specific share
2sudo umount /mnt/samba
3
4# Force unmount if busy
5sudo umount -l /mnt/samba # Lazy unmount
6sudo umount -f /mnt/samba # Force unmount
7
8# Check what's using the mount
9lsof +D /mnt/samba

Checking Mount Status

bash
1# View all mounted filesystems
2mount | grep cifs
3
4# Check mount details
5findmnt /mnt/samba
6
7# Show space usage
8df -h /mnt/samba
9
10# Test read/write access
11touch /mnt/samba/test.txt && rm /mnt/samba/test.txt