(Unix) Store & use credentials for fstab

This is useful when auto-mounting by /etc/fstab is disabled due to the mount requiring login credentials every time.

  1. Create a credentials file under /root AS ROOT using sudoedit, e.g.:
    sudoedit /root/<CREDENTIALS_FILENAME>`
    
  2. In the editor, write the login credentials for a given mount:
    username=<MOUNT_USERNAME>
    password=<MOUNT_PASSWORD>
    
  3. Confirm that the user of the new file is root:
    sudo ls -al /root | grep <CREDENTIALS_FILENAME>
    
  4. Change permissions of the file so that the file can be read/written only as root:
    sudo chmod 600 /root/<CREDENTIALS_FILENAME>
    
  5. In /etc/fstab, specify credentials= option under -o flag of the mount of interest:
    ... -o ...,credentials=/root/<CREDENTIALS_FILENAME>,... ...
    
  6. Test that the credentials work:
    sudo mount -av
    

References:

Written on May 2, 2022