If you have to mount a share from an unreliable (in terms of “won’t be available 24/7) windows machine, using the traditional way with mount.cifs
and /etc/fstab
is a pain in the ass, since you will have to remount manually every now and then.
Let’s use the much better way with autofs:
We assume, that you want to mount your private “Documents” windows share from the machine with the IP address 192.168.1.116:
- Install autofs:
sudo apt-get install autofs
- As root, add the following line to
/etc/auto.master
:/cifs /etc/auto.smb.top --timeout=60
This line is used to check every 60 seconds for all potentially available smb shares to mount under
/cifs
. - Create as root
/etc/auto.smb.top
with the following content:* -fstype=autofs,-Dhost=& file:/etc/auto.smb.sub
This simple line tries to mount everything from all smb hosts with a little help of
/etc/auto.smb.sub
- Create as root
/etc/auto.smb.sub
with the following content:* -fstype=cifs,credentials=/home/youruser/.smbcredentials,uid=1000,gid=100 ://${host}/&
Here, you assign your smb credentials, which reside in
/home/youruser/.smbcredentials
: - Create as your user
/home/youruser/.smbcredentials
with the following content:username=yourwindowsusername password=yourwindowspassword
Set its file rights to 600 with
chmod 600 /home/youruser/.smbcredentials
- Finally, restart the autofsservice as root with
service autofs restart
Now you can access (or symlink) your windows share “Documents” under /cifs/192.168.1.116/Users/yourwindowsuername/Documents
and you don’t have to worry any more about unresponsive windows shares, which block your file manager.
Credits go to the CentOS Wiki, which gave the idea at https://wiki.centos.org/TipsAndTricks/WindowsShares