Mounting windows shares in a robust way

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

  1. Install autofs: sudo apt-get install autofs
  2. As root, add the following line to /etc/auto.master:
    /cifs /etc/ --timeout=60

    This line is used to check every 60 seconds for all potentially available smb shares to mount under /cifs.

  3. Create as root /etc/ 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

  4. 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:

  5. Create as your user /home/youruser/.smbcredentials with the following content:

    Set its file rights to 600 with chmod 600 /home/youruser/.smbcredentials

  6. Finally, restart the autofsservice as root with service autofs restart

Now you can access (or symlink) your windows share “Documents” under /cifs/ 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