Quick start guide to mounting SMB/CIFS shares manually and on system boot. This guide is designed for Ubuntu 24.04 but it will almost certainly work with any flavour of modern linux.
Create SMB Share
I'm using Unifi UNAS but this will work with any server that support SMB3 protocol. Create a folder and a user that has permission to read/write to it.
A safe way to store the credentials for auto-mounting is via a file in the server home directory. I keep mine in ~/.credentials/cifs-[sharename]
for consistency across all servers.
For the rest of the article lets assume the share is called share1
on the SMB server and the username for access is called marc
.
username=marc
password=p@55w0rd
Install dependencies
The following packages are required to correctly mount cifs/smb 3+ shares on ubuntu. If you get an error such as mount: /mnt/cifs-share1: cannot mount //192.168.1.123/share read-only
it's because one of these packages is missing.
sudo apt install cifs-utils psmisc
Manually mount the share
Run the following command to manually mount and verify that the connection succeeds.
sudo mkdir /mnt/cifs-share1
sudo mount -t cifs -o credentials=/home/ubuntu/.credentials/cifs-share1 //192.168.1.123/share1 /mnt/cifs-share1
Once mounted you can verify you have access to the files with ls
:
ls -l /mnt/cifs-share1
Mount on system boot
In order to ensure this is auto mounted you need to add the following data to /etc/fstab
.
//192.168.1.123/share1 /mnt/cifs-share1 cifs credentials=/home/ubuntu/.credentials/cifs-share1,uid=1000,gid=1000,file_mode=0775,dir_mode=0775 0 0
Restart your server then run the ls
command again to verify the mount worked automatically.
I had issues with one specific machine where the network link would not come up until after the mount was attempted which resulted in no shares mounted on boot. You can append the following mount options if you see similar problems. This will mount the share the first time it is accessed instead of when the system boots.
_netdev,noauto,x-systemd.automount