Mount a NAS Share on Ubuntu
Need your Ubuntu server to automatically mount a shared folder from your NAS at boot? This guide uses CIFS/SMB, which is supported by most NAS devices (Synology, QNAP, TrueNAS, Unraid, Windows shares, etc.).
1. Install the required package
sudo apt update
sudo apt install cifs-utils
2. Create a mount point
Choose where you want the share to appear.
sudo mkdir -p /mnt/nas
3. Store your credentials
Create a credentials file:
sudo nano /etc/samba/credentials
Warning
If the /etc/samba directory exists (it usually does after installing cifs-utils), simply run:
sudo nano /etc/samba/credentials
Add the following in the credentials file
username=YOUR_USERNAME
password=YOUR_PASSWORD
Save the file and secure it:
sudo chmod 600 /etc/samba/credentials
4. Add the mount to /etc/fstab
Edit the file:
sudo nano /etc/fstab
//192.168.1.100/Media /mnt/nas cifs credentials=/etc/samba/credentials,iocharset=utf8,uid=1000,gid=1000,file_mode=0664,dir_mode=0775,nofail,_netdev 0 0
Warning
Make sure you change the //192.168.1.100/Media to your Share's address and the /mnt/nas to where you would like it mounted
Common options
| Option | Description |
|---|---|
credentials= |
Uses the credentials file |
uid=1000 |
Makes your user the owner |
gid=1000 |
Sets the group |
file_mode=0664 |
Default file permissions |
dir_mode=0775 |
Default directory permissions |
_netdev |
Waits for the network before mounting |
nofail |
Allows boot even if the NAS is offline |
5. Test the configuration
Without rebooting:
sudo mount -a
If there are no errors, verify it mounted:
df -h
or
mount | grep cifs
6. Verify access
List the contents:
ls /mnt/nas
You should now see the files stored on your NAS.