Mount a Network Share in Linux (fstab)
This guide covers how to mount a Samba (SMB) share or an NFS share permanently in Linux using /etc/fstab. Useful for accessing shared folders from a NAS, Windows machine, or another Linux server in your home lab.
Mount a Samba (SMB) Share
Step 1 – Install the SMB Client
sudo apt update
sudo apt install -y cifs-utilsStep 2 – Create a Mount Point
sudo mkdir -p /mnt/nas-shareStep 3 – Create a Credentials File
Store your username and password in a separate file instead of putting them in fstab (which is readable by all users):
sudo nano /etc/samba/credentialsAdd:
username=yourusername
password=yourpasswordSecure the file:
sudo chmod 600 /etc/samba/credentials
sudo chown root:root /etc/samba/credentialsStep 4 – Add to fstab
sudo nano /etc/fstabAdd this line (replace IP, share name, and your username):
//192.168.1.100/sharename /mnt/nas-share cifs credentials=/etc/samba/credentials,uid=1000,gid=1000,iocharset=utf8,_netdev 0 0What the options mean:
credentials=...— path to your credentials fileuid=1000,gid=1000— your user and group ID (check withidcommand)iocharset=utf8— handle special characters correctly_netdev— wait for network before mounting
Step 5 – Test
sudo mount -aVerify:
df -h | grep nas-share
ls /mnt/nas-shareMount an NFS Share
Step 1 – Install the NFS Client
sudo apt update
sudo apt install -y nfs-commonStep 2 – Create a Mount Point
sudo mkdir -p /mnt/nfs-shareStep 3 – Find Available NFS Exports
Check what the NFS server is sharing:
showmount -e 192.168.1.100Step 4 – Test Mount Manually
sudo mount -t nfs 192.168.1.100:/path/to/share /mnt/nfs-shareStep 5 – Add to fstab
sudo nano /etc/fstabAdd:
192.168.1.100:/path/to/share /mnt/nfs-share nfs defaults,_netdev 0 0Test:
sudo mount -aTroubleshooting
Mount fails after reboot:
Make sure _netdev is in your fstab options — this tells the system to wait for the network before attempting the mount.
Permission denied on SMB share:
Check that uid and gid match your user. Find your IDs with:
idCan’t see the NFS export:
Make sure nfs-common is installed and the NFS server allows your IP in its exports config.
Quick Reference
| Command | What it does |
|---|---|
sudo mount -a |
Mount all fstab entries |
sudo umount /mnt/nas-share |
Unmount a share |
df -h |
Show mounted shares and usage |
showmount -e 192.168.1.x |
List NFS exports from a server |
id |
Show your user and group IDs |
Related Links
- Mount a Disk in Linux (fstab) — mount internal and external disks
- Set Up Samba File Sharing on Linux — create your own Samba share
- Arch Wiki – fstab — detailed fstab documentation