« HOWTO:Set up NFS sharingHOWTO Sort out kvm »

HOWTO Setup and Configure Autofs

21/07/08

HOWTO Setup and Configure Autofs

Autofs And Cifs/Samba Shares.

I'm assuming you have Samba/Cifs already setup. If not there are loads of HOWTOs out there and this one is getting way too long already.

Setting up the shares is really really simple. The default install of autofs supplies a script /etc/auto.smb This is really good, although I have modified it slightly to get it to work the way I wanted. I do not want to automatically mount the hidden samba shares. Those that end with a '$'. I also added an extra check for a default credentials file when a specific server file does not exist.

Get my updated version here
and save it as /etc/auto.smb, but backup your original file first. Just to save confusion remove the executable flags from the file too.

cd /etc  sudo mv auto.smb auto.smb.org  sudo chmod 644 /etc/auto.smb.org  sudo cp <where/you/downloaded/auto.smb.txt auto.smb
sudo chmod 755 /etc/auto.smb

You can test this file is working simply by running it from the command line. I'm using a VMware machine that is running Windows 2K and is called imaginatively vmwin2ksamba. It has four shares, The entire C: and E: drives along with the downloads and Temp directories.

$ sudo /etc/auto.smb vmwin2ksamba
-fstype=cifs,credentials=/etc/auto.smb.credentials \  
         /Downloads ://vmwin2ksamba/Downloads \  
         /C_DRIVE ://vmwin2ksamba/C_DRIVE \  
         /E_DRIVE ://vmwin2ksamba/E_DRIVE \  
         /Temp ://vmwin2ksamba/Temp  

The script actually creates on the fly, the second and third parameters for a map file in multimap mode. See the autofs(5) man page for a very brief explanation of multimap mode.

To use /etc/auto.smb add a line to the /etc/auto.master and then restart the autofs daemon and try it out. I also add the nonstrict option to the map line, without it if any one of the connections or shares is wrong or you do not have permission then the whole thing breaks. Also I have a user samba who's gid=1001 and uid=1001. This user cannot run a login shell and is therefore a little more secure. See the Samba docs, they explain it much better than I do.

Example:/etc/auto.master
/winshare       /etc/auto.smb    --timeout=300,nonstrict,gid=1001,uid=1001
sudo /etc/init.d/autofs restart

You can now look at the directory winshare/vmwin2ksamba and see all the available shares.

$ ll /winshare/vmwin2ksamba/  
total 0  
drwxrwxrwx 1 samba samba 0 2008-04-13 08:42 C_DRIVE/  
drwxrwxrwx 1 samba samba 0 2007-12-20 10:42 Downloads/  
drwxrwxrwx 1 samba samba 0 2008-04-13 08:52 E_DRIVE/  
drwxrwxrwx 1 samba samba 0 2008-04-13 12:31 Temp/  

You may have to setup a credentials file to get access to all the shares on your network. The credentials file is from the default file /etc/auto.smb.<windows host > or with my modified version you can use a fall back file /etc/auto.smb.credentials. The file format is one key = value pair per line as in the following. I don't use the domain value and it still works ok.

Example share configuration
username = <name>  
password = <password>  
domain = <domain> 

Pages: 1 · 2 · 3 · 4 · 5 · 6 · 7 · 8 · 9 · 10

No feedback yet

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
PoorExcellent
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
What can birds and aeroplanes both do?
antispam test