Creating credential files for automatic Samba mounts in /etc/fstab

It’s handy to have credentials for each Samba server so you don’t have public passwords in /etc/fstab for the Samba file systems you want to mount on boot. Here’s how I do it:

  1. Create a directory /etc/samba/credentials
  2. Create a file /etc/samba/credentials/myserver
  3. In the myserver file, put the credentials for that server:

    Note: spaces are important here – don’t use “ = ”, use “=”.

  4. chown -R root.root /etc/samba/credentials
  5. chmod 700 /etc/samba/credentials
  6. chmod 600 /etc/samba/credentials/myserver

Once this is done, you can add lines for each mount of that server to your /etc/fstab:

//myserver/music        /music  smbfs   credentials=/etc/samba/credentials/myserver 0 0
//myserver/shared       /shared smbfs   credentials=/etc/samba/credentials/myserver 0 0

Note that the file in /etc/samba/credentials doesn’t have to be named the same thing as the server name – it just makes it easier.

This also survives the Ubuntu upgrade process, so you just have to update /etc/fstab if you upgrade to a new release, and can keep the same credentials files.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: