Technical Anshu
Tutorials Blog
Linux Security

Keep Your Share Password Safe With a Credentials File

The most copied fstab examples on the internet put your Windows password in plain text, in a file every account on the machine can read. The credentials file fixes that in four commands, and it is the way permanent share mounts are supposed to be done.

Technical AnshuUbuntu and WindowsStep-by-step guide
Watch the video for the complete process shown live, step-by-step

Search for how to mount a Windows share and half the results will show an fstab line containing password=YourPassword in the open. It works - that is exactly the problem. /etc/fstab has no secrets: any user, any guest session, any program running as any account can read it. If your Windows password is in there, it is not stored, it is published - to everyone who can log in to that PC. The credentials file is the standard answer: the password moves into a file owned by root and readable by root alone, and fstab keeps only a pointer to it. This page builds it, locks it, and proves the lock.

File permissions compared - where the secret actually lives
/etc/fstab-rw-r--r--  everyone can read
/root/.smbcredentials-rw-------  root only
✓ Fstab holds a pointer: credentials=/root/.smbcredentials - and no password at all
✗ Fstab holding password= in plain text - the habit this page replaces
The whole idea in two lines: same password, two very different audiences. The permission string -rw------- is the lock this page sets.
1

The Problem - Fstab Is a Public Noticeboard

Ubuntu sets /etc/fstab to permissions 644: the owner can write it, everyone else can read it. That is fine for disk definitions and a disaster for secrets. Run cat /etc/fstab from any ordinary account and you will see every line, including any password someone pasted into a mount option. Passwords placed directly in a mount command have a second exposure too - they can appear in shell history and, on some setups, in the process list while the mount runs.

  1. If your current fstab line contains a password, treat it as shared from today - this page is how you retire it properly
  2. The fix is not a cleverer place inside fstab. The secret has to leave the file entirely
2

Create the Credentials File With Exactly Two Lines

The file lives in root's home, because mounts are performed by root at boot - root must be able to read its own file.

  1. Create and open it: sudo nano /root/.smbcredentials
  2. First line: username=anshu
  3. Second line: password=YourWindowsPassword
  4. Optional third line when the Windows PC asks for one: domain=WORKGROUP
  5. Format rules that cause real failures: no spaces around the equals sign, no quotes around the password, and no trailing spaces at the end of a line
3

Lock It Down - chmod 600 Is the Whole Point

A credentials file with loose permissions is the original problem wearing a new name. The permission change is not decoration; it is the mechanism.

  1. Apply it: sudo chmod 600 /root/.smbcredentials
  2. 600 means: owner (root) can read and write, group and everyone else get nothing - no read, no write, no entry
  3. Verify, do not assume: sudo ls -l /root/.smbcredentials must show -rw------- and owner root
  4. Prove it from the other side: as your normal user, cat /root/.smbcredentials should answer Permission denied. That refusal is the feature working
4

Point Fstab at the File and Retire the Old Password

Now the fstab line swaps its secret for a pointer.

  1. Edit: sudo nano /etc/fstab and replace username=anshu,password=... with credentials=/root/.smbcredentials in the options, keeping the rest of the line as the core guide built it
  2. Refresh and remount: sudo systemctl daemon-reload, then sudo umount /mnt/SharedDocs and sudo mount -a
  3. Confirm the share is back and the files are visible: ls /mnt/SharedDocs
  4. Clear the other copies of that password: your shell history (history) if a mount command ever contained it, and any notes file you drafted the line in
🔴 Honest limits, stated plainly: chmod 600 stops other user accounts on a running system. It does not stop root, and it does not stop someone who removes the disk and reads it on another machine - only disk encryption answers that. What the credentials file does, it does properly: your Windows password stops being readable by every casual login on the PC, which is where the real-world risk actually lives.

Watch the Complete Video Guide

Watch the video for the full permanent setup, including where this credentials file fits into the fstab line.

Watch Full Video
Common Questions (FAQ)

Why does the credentials file live in /root and not in my home folder?

Because the mount is performed by root during boot, before your home folder is guaranteed to be available - on systems with encrypted home folders it may not be readable at all until you log in. /root is always there, always root-owned, and already protected. A credentials file in your home can also silently break the day home permissions or encryption change.

Can one credentials file serve several shares?

Yes, when the shares accept the same account - simply point each fstab line at the same file. Use separate files when the accounts differ, for example one for the Windows PC and another for a NAS, so a password change on one device only ever means editing one small file.

The mount says permission denied after I switched to the credentials file. What is wrong?

Almost always the file's format, not its permissions: a space beside the equals sign, quotes typed around the password, or an invisible trailing space will all make the credentials wrong while looking right. Retype the two lines cleanly in nano, and if you edited the file on Windows at any point, recreate it - Windows line endings have broken many credentials files.

This guide is based on the Technical Anshu video on mounting a Windows share in Ubuntu - stuck on any step, ask in the video comments and you will get an answer.