Mounting NAS using autofs

NAS
nfs
cifs
autofs
Author

Peter Pham

Published

February 8, 2026

Overview

autofs is a great tool to mount your network storage more efficiently on your Linux server. These are the benefits of using autofs:

  • Persistence: Mounts persist across restarts
  • On-demand mounting: Mounts are only established when accessed, reducing boot time and system overhead
  • Reduced network traffic: Unneeded shares remain unmounted, saving bandwidth
  • Automatic retry: Automatically retries connection if the NAS is temporarily unavailable
  • Support for multiple protocols: Works with NFS (NFSv3, NFSv4), CIFS/SMB, FTP, and more
  • Ghost directories: The --ghost option creates placeholder directories for easier browsing

Configuration

  1. Install the required autofs. The following instruction assumes you have a Debian/Ubuntu OS.
sudo apt update && sudo apt install -y autofs cifs-utils
  1. Create your NAS credential file:
sudo mkdir -p /etc/samba/credentials
sudo nano /etc/samba/credentials/nas.cred

nas.cred:

username=myuser
password=supersecretpassword
domain=MYDOMAIN   # optional, omit if not needed

Protect your credentials from non-root users:

sudo chmod 600 /etc/samba/credentials/nas.cred
sudo chown root:root /etc/samba/credentials/nas.cred
  1. Configure the master autofs master mapping:
sudo nano /etc/auto.master

/etc/auto.master:

# Assuming you want to mount to `/mnt/smb` locally to your NAS:
/mnt/smb  /etc/auto.cifs  --timeout=300 --ghost
  1. Create a new map file:
sudo nano /etc/auto.cifs

/etc/auto.cifs:

# Assuming your NAS is located at 192.168.2.223 with shares: vm, iso
vm  -fstype=cifs,_netdev,credentials=/etc/samba/credentials/nas.cred,vers=3.1.1,serverino ://192.168.2.223/vm
iso -fstype=cifs,_netdev,credentials=/etc/samba/credentials/nas.cred,vers=3.1.1,serverino ://192.168.2.223/iso
  1. Restart autofs to pick up the updated configuration:
sudo systemctl restart autofs
  1. Check your files:
# should show files from your NAS `vm` path!
cd /mnt/smb/vm

Troubleshooting

Check autofs status

sudo systemctl status autofs

Run in debug mode

sudo automount -f -v -v

Force mount manually

sudo mount -a

View mount logs

journalctl -u autofs -f

Common issues

Issue Solution
Mount fails with “No such file or directory” Check NAS IP and share name in map file
Mount fails with “Permission denied” Verify credentials file permissions and contents
Mount hangs Add soft,intr options or check network connectivity
Files show as wrong owner Add uid and gid options to map