How to Fix NFS Mount in /etc/fstab with Password Authentication


2 views

When trying to automatically mount an NFS share with credentials at boot, many administrators encounter issues where the mount fails despite correct manual mounting. The key difference lies in how credentials are handled between manual mounts and fstab entries.

The manual mount command that works:

mount //192.168.0.1/NASShare -o username=administrator,password=pass /mnt/NAS

The problematic fstab entry:

192.168.0.1:/NASShare  /mnt/NAS  nfs user=administrator,password=pass  0 0

The main issues with the current fstab approach:

  • NFS protocol doesn't use username/password in the same way as CIFS/SMB
  • Credential syntax for fstab differs from mount command
  • NFS typically relies on host-based authentication rather than user credentials

For NFS shares, we should use either:

Option 1: Host-based Authentication

192.168.0.1:/NASShare  /mnt/NAS  nfs  rw,hard,intr  0  0

Option 2: Credentials File (More Secure)

First create a credentials file (/etc/nfs_creds):

username=administrator
password=pass

Then modify fstab:

192.168.0.1:/NASShare  /mnt/NAS  nfs  rw,hard,intr,credentials=/etc/nfs_creds  0  0

If mounts still fail, check:

# Check NFS server exports
showmount -e 192.168.0.1

# Test mount manually
mount -t nfs 192.168.0.1:/NASShare /mnt/NAS -vvv

# Examine system logs
journalctl -xe

For more flexible mounting:

# Install autofs
apt install autofs

# Configure /etc/auto.master
/mnt/NAS  /etc/auto.nas  --timeout=60

# Create /etc/auto.nas
NASShare  -fstype=nfs,rw,hard,intr  192.168.0.1:/NASShare

When mounting NFS shares that require authentication, many Linux administrators encounter issues during boot time. The manual mount command works perfectly:

mount //192.168.0.1/NASShare -o username=administrator,password=pass /mnt/NAS

But the corresponding fstab entry fails to mount automatically at boot:

192.168.0.1:/NASShare  /mnt/NAS  nfs user=administrator,password=pass  0 0

The main issue here is mixing CIFS/SMB syntax with NFS protocol. The manual command uses SMB-style authentication while trying to configure an NFS mount in fstab. These are fundamentally different protocols with different authentication mechanisms.

For NFS mounts, authentication typically happens differently:

192.168.0.1:/NASShare  /mnt/NAS  nfs  rw,hard,intr,timeo=300,retrans=3  0  0

NFS usually relies on host-based authentication through /etc/exports on the server rather than username/password credentials. However, if you specifically need password authentication, consider these alternatives:

# /etc/auto.master
/mnt/NAS /etc/auto.nas --timeout=60

# /etc/auto.nas
NASShare -fstype=cifs,credentials=/etc/nas.cred,rw,file_mode=0664,dir_mode=0775 ://192.168.0.1/NASShare

# /etc/nas.cred
username=administrator
password=pass

For enterprise environments, NFSv4 with Kerberos provides secure authentication:

192.168.0.1:/NASShare /mnt/NAS nfs4 sec=krb5,rw,hard,intr 0 0
  • Mixing protocol types (NFS vs SMB) in fstab
  • Storing plaintext passwords in fstab (use credential files instead)
  • Not verifying network availability before mount attempts
  • Using soft mounts for critical data

Use these commands to troubleshoot:

# Check system logs
journalctl -xe

# Test mount manually
mount -av

# Verify NFS export availability
showmount -e 192.168.0.1