How to auto mount a windows share on CentOS 7 (RHEL)

Following is a step by step guide on how to auto mount a windows share on CentOS 7 or other RHEL based operating systems (Fedora, etc.). First we'll need to...

Following is a step by step guide on how to auto mount a windows share on CentOS 7 or other RHEL based operating systems (Fedora, etc.).

First we'll need to install the AutoFS (this is an auto-mounter)

yum install autofs

Now if you do not have it installed already, install samba (client)

Samba is an Open Source/Free Software suite that provides seamless file and print services to SMB/CIFS clients.

yum install samba-client samba-common

As a next step, go and open /etc/auto.master file, scroll right to the bottom of it, enter following and save the file:

/mnt/windows    /etc/auto.win    --timeout=600 --ghost

Ok, let's create the mount point:

mkdir /mnt/windows

Now we need to create the file /etc/auto.win which we've earlier referenced in the auto.master file. So go ahead and create auto.win in /etc folder and type in:

share    -fstype=cifs,rw,noperm,credentials=/etc/autofscredentials.txt    ://192.168.0.x/windows_share

Note: replace '://192.168.0.x/windows_share' with the path to your own Windows share

As a last step, we'll create the autofscredentials.txt file, where we'll store our windows share login name and password. So create the file, enter and save following:

username=windows_share_username
password=windows_share_password

Now all that you need to do is to setup autofs service to start on boot, run following command:

systemctl enable autofs.service

And you're all done. To see your Windows share in Centos 7, go to /mnt/windows folder:

cd /mnt/windows