Tuesday, February 7, 2012

CIFS Automount in Linux

Assuming that you have autofs installed and running, add an appropriate entry in /etc/auto.master like so:
/mnt/smb /etc/auto.smbfs --timeout=120

Inside /etc/auto.smbfs (make it executable (chmod +x /etc/auto.smbfs)):
* -fstype=autofs,-Dhost=& file:/etc/auto.smb.sub

And inside /etc/auto.smb.sub, you have a few choices:

If you want to set the uid and gid of the credentials accessing the CIFS share (this defaults to read only):

* -fstype=cifs,credentials=/etc/cifssecret.txt,uid=101,gid=101 ://${host}/& 

otherwise:

* -fstype=cifs,credentials=/etc/cifssecret.txt,rw ://${host}/&
This will let you connect to any samba server or windows server on the mount point
/mnt/smb/servername/share_name




Of course, if you want to hard code the CIFS server name and share:

* -fstype=cifs,credentials=/etc/cifssecret.txt,rw ://mycifsserver/the_share_you_want
 
Inside /etc/cifssecret.txt:

username=yoursambaOrCIFSuser
password=yourcifspassword

chown root /etc/cifssecret.txt
chmod 400 /etc/cifssecret.txt

restart autofs:

sudo /sbin/service autofs restart

And do a listing of some server on that share:

ls /mnt/smb/myWindowsServer/share1