Requirements¶To install AutoFS you will need the following:
- a installed and supported operating system (e.g. CentOS 6.x)
- a fast internet connection
Before setting up autofs we need to create a network share on the Windows PC. Remember the user and the password since we’ll need them later on. In this article I’m going to assume the user name is backup and the password is secret but you should use something more difficult to guess depending on your security requirements. I’m also assuming the Windows domain is called company.
Install AutoFS by logging into a Terminal as root:
yum install autofs
You need to edit
/etc/auto.master file and add this line
/smb /etc/auto.windows --timeout=60
Then you create the file
/etc/auto.windows containing the following, in a single line:
<share> -fstype=smbfs,credentials=/etc/auto.windows.<credentials pre>,uid=<user>,gid=<group>,fmask=0755,dmask=0755 ://<windows PC>/<network share>
This must be written on a single line, with no separating spaces starting from
<share> is the name of directory where you want to mount the network share from Windows PC.
/etc/auto.windows.<credentials pre> is the name of file where you store the user name and password needed to access the network share on Windows PC. In our case it will look like this:
username = backup password = secret domain = company
After these preparations it’s time to tell the autofs daemon about these changes by executing
service autofs reload or a corresponding command. You should be able now to see that the network share gets automatically mounted when you execute
ls /smb/<share>. After 60 seconds the share will be unmounted.