Accessing Windows Or Samba Shares Using AutoFS

You already installed Linux on your networked desktop PC and now you want to work with files stored on some other PCs in your network. This is where autofs comes into play. This tutorial shows how to configure autofs to use CIFS to access Windows or Samba shares from Linux Desktop PCs. It also includes a tailored configuration file.

If autofs Version 4.0 or newer is already installed, you should find the files




on your system. Otherwise start the package manager of your distribution (e.g. YaST on SuSE, synaptic on Debian or Ubuntu, ...) and install it. When you are at it, also install the Samba client package (look for smbclient), because we will also need this. On some distributions (Ubuntu) we also need the package smbfs which contains the utilities mount.cifs and umount.cifs.


If autofs is already installed, it is probably still not configured and not working. Assuming your Linux Distribution contains a Linux 2.6.x kernel I recommend to use the common internet file system (cifs) module to access files on the network. Please store the following file as


on your computer. You need root (or sudo) to have the permissions to do this:

# $Id$
# This file must be executable to work! chmod 755!
# Note: create a cred file for each windows/Samba-Server in your network
#       which requires password authentification.  The file should contain
#       exactly two lines:
#          username=user
#          password=*****
#       Please don't use blank spaces to separate the equal sign from the
#       user account name or password.
# Note: Use cifs instead of smbfs:
for P in /bin /sbin /usr/bin /usr/sbin
        if [ -x $P/smbclient ]
[ -x $SMBCLIENT ] || exit 1
if [ -e "$credfile" ]
        smbclientopts="-A "$credfile
$SMBCLIENT $smbclientopts -gL $key 2>/dev/null \
   | awk -v key="$key" -v opts="$mountopts" -F'|' -- '
        BEGIN   { ORS=""; first=1 }
	/Disk/  { if (first) { print opts; first=0 };
		  gsub(/ /, "\\ ", $2);
		  sub(/\$/, "\\$", $2);
		  print " \\\n\t /" $2, "://" key "/" $2 }
        END     { if (!first) print "\n"; else exit 1 }

Make this file executable using the command:

chmod 755 /etc/auto.cifs

This file is a slightly modified version of the file auto.smb which usually comes as part of the autofs package. You need to modify the line defining the mountopts above and change user to the name of your personal account name. Now you have to give autofs the credentials needed to access shares on your network. To do this create a file called


for each computer you want to access. Of course replace FILESERVERNAME with the name of the computer. Fill these files with user account name and password needed to access the shares on the computer. The content of these files should like the following example:


Use the command

chmod 600 /etc/auto.smb.*

to protect the password information.

Now we have to tell autofs to make use of our new configuration file. Use the commands:

echo "/cifs /etc/auto.cifs --timeout=60" >>/etc/auto.master


/etc/init.d/autofs restart

That's all.


Use the command


to check, if it works. If not, consult the system logfiles (usually /var/log/messages or /var/log/syslog) for messages.

Credits: davek for providing a patch to better escape dollar signs and blanks in share names

Share this page:

24 Comment(s)