Skip to main content

The Sysadmin’s Guide to Secure, Persistent Samba Mounts in Linux

Updated 3 min readMarkdown

If you’ve ever found yourself fighting with /etc/fstab to get a network share to mount reliably after a reboot, you aren't alone. Between user-space permission locks and credential handling, it’s a classic point of failure for anyone building a home lab.

I recently spent some time cleaning up my own cross-platform network shares between my Linux (CachyOS) and Windows machines, and I learned a few things about moving from a "it works for now" setup to a "this is production-ready" configuration.

The Problem If you’re like me, you might have started by hardcoding credentials in your fstab or relying on insecure guest access (e.g., Set-SmbClientConfiguration -EnableInsecureGuestLogons $true). While that works to get the folder mounted, it’s a security nightmare and can lead to persistent connection loops or "permission denied" errors when the systemd daemon tries to mount the drive before the network is fully initialized.

The Solution: Credential Files & Strict Permissions To fix this, the best practice is to move credentials out of the config file entirely and into a dedicated, root-owned file. Here is how I secured my setup:

  1. Create a Secure Credentials File Instead of putting your username and password in /etc/fstab, create a dedicated directory for your credentials.
# Create the directory if it doesn't exist
sudo mkdir -p /etc/samba/credentials/

# Create your credential file
sudo nano /etc/samba/credentials/myshare.cred

Add your credentials to this file:

username=your_username
password=your_password
domain=WORKGROUP

2. Lock Down Permissions

This is the most important step. You want to make sure only the root user can read this file.

sudo chmod 600 /etc/samba/credentials/myshare.cred

3. Update /etc/fstab

Now, update your /etc/fstab to reference the credential file using an absolute path. This avoids issues where the system tries to look in a home directory that isn't mounted yet.

//server_ip/share /mnt/mountpoint cifs credentials=/etc/samba/credentials/myshare.cred,iocharset=utf8,uid=1000,gid=1000 0 0

4. Finalize and Automate

After saving your changes, always ensure your system acknowledges the new mount configuration:

sudo systemctl daemon-reload
sudo mount -a

Why this matters

By moving away from hardcoded credentials and guest access, you’ve accomplished three things:

  1. Security: Your plaintext password is no longer sitting in a world-readable config file.

  2. Stability: Using an absolute path to a root-owned file ensures the mount can be processed by systemd regardless of which user is logged in.

  3. Cleanliness: Your fstab is now clean, readable, and professional.

Documentation is the difference between a hobbyist and a systems administrator. By spending the time to fix this properly, you stop "fighting" your network and start building infrastructure you can rely on.

Have you struggled with Samba mounts in the past? Let me know in the comments how you handle your persistent network storage!

25 views

About the author

  • Hi, I'm Randall. I’m a systems enthusiast and tinkerer currently transitioning into a professional career as a Linux Systems Administrator. My day-to-day involves building out high-performance home infrastructure and pushing the boundaries of local AI model training on AMD hardware. I’ve spent years obsessing over performance and stability, which has led me down a rabbit hole of: Linux Distribution Optimization: Currently living in the worlds of Nobara and CachyOS. Infrastructure: Managing a 10Gbps home network and fine-tuning cross-platform Samba shares. AI/ML Ops: Working with ComfyUI, RDNA 4 architecture, and navigating the complexities of Python virtual environments to keep training pipelines stable. I’m a firm believer that the best systems are the ones you build yourself. Whether I’m troubleshooting a kernel issue or configuring a network switch, I believe in documentation as a practice—not just for others, but for the clarity it brings to the work itself. I’m moving to Knoxville soon and looking forward to connecting with the local tech and DIY communities there.

No comments yet. Be the first to comment.