Automounting Windows CIFS Shares

It can be very useful to mount a Windows (CIFS) Share on a Linux system. It's super easy to setup automount to go to mulitple servers and multiple shares on those servers using automount.

The goal is to tell automount to pickup the hostname and share from the path, so that a user can simple do:

cd /mnt/hostname/share

Use these setup to set this up:

Install autofs:

yum install autofs

Add a few lines to auto.master:

echo "/mnt /etc/auto.smb-root.top" >> /etc/auto.master

This tells autofs that "/mnt" is managed by autofs.

Create /etc/auto.smb-root.top:

echo "* -fstype=autofs,rw,-Dhost=& file:/etc/auto.smb.sub" > /etc/auto.smb-root.top

Create /etc/auto.smb.sub:

echo "* -fstype=cifs,rw,credentials=/etc/${host:-default}.cred ://${host}/&" > /etc/auto.smb.sub

Create a credentials file for each server:

cat << EOF > /etc/hostname.cred
username=WindowsUsername
password=WindowsPassword
domain=WindowsDomain
EOF

And create a file with default credentials:

cat << EOF > /etc/default.cred
username=WindowsUsername
password=WindowsPassword
domain=WindowsDomain
EOF

Restart autofs:

service autofs restart

Now you should be ready to cd into /mnt/hostname/share. You will notice this takes a second or so to complete, this second is used to mount the share and present you with the data directly.

One drawback of this solution; the username/password is assigned to the hostname, so if a share requires a different username/password, that's a problem.

About Consultancy Articles Contact




References Red Hat Certified Architect By Robert de Bock Robert de Bock
Curriculum Vitae By Fred Clausen +31 6 14 39 58 72
By Nelson Manning robert@meinit.nl