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:
-
Create a directory /etc/samba/credentials
-
Create a file /etc/samba/credentials/myserver
-
In the myserver file, put the credentials for that server:
username=myusername password=mypassword
Note: spaces are important here - don’t use “ = ”, use ”=”.
-
chown -R root.root /etc/samba/credentials
-
chmod 700 /etc/samba/credentials
-
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.