Linux: Automount Windows or Samba shares

Hi,

today I will explain how to easy it is to automatically mount a windows share on linux.

The following packages are necessary: autofs, cifs/samba client tools

In this example I use a debian linux system.

root@dev # apt-get install autofs cifs-utils

edit the auto.master file with your favorite editor:

root@dev # vi /etc/auto.master

add the following line

/media/cifs /etc/auto.cifs --ghost

  • /media/cifs – is the root directory where the mount points are created (this is not the mount point itself!), the directory must exist.
  • /etc/auto.cifs – the definition file of the mount points
  • --ghost This option will create the mount point permanently, even the share isn’t mounted (there are doubledashes before ghost:-))

Create a new file /etc/auto.cifs and add your share definition. In this example the Windows computer is mediaserver with the share multimedia$ (Note: you have to quote the $ character in auto.cifs file or you got  cifs_mount failed w/return code = -6). The share should be mounted as user michl which has UID 1000 and GID 1000. Insert the following line to /etc/auto.cifs:

root@dev # touch /etc/auto.cifs

root@dev # vi /etc/auto.cifs

multimedia -fstype=cifs,credentials=/root/cred_mediaserver,uid=1000,gid=1000 ://mediaserver/multimedia\$

Whats left is to define the Windows User which have the appropriate rights to connect. Create the file /root/cred_mediaserver

root@dev # touch /root/cred_mediaserver

Set only permission for user root to read the file

root@dev # chmod 600 /root/cred_mediaserver

root@dev # vi /root/cred_mediaserver

and insert 2 lines. One with the Username and one with the password:
username=michl
password=michlsPassword

Note: Be carefully with special characters in your password. Some have to quote because there are running shell scripts in background of the automounter! If you have a domain login use domain/username as username.

Start the automounter if it isn’t already started.

root@dev #/etc/init.d/autofs start

Then accessing the mount point /media/cifs/multimedia. The share is now mounted. If not see /var/log/syslog for details.

Michael

One thought on “Linux: Automount Windows or Samba shares”

  1. is this the expected error msg. for this kind of attempt:
    kernel: CIFS VFS: Unexpected lookup error -6
    And how about:
    kernel: CIFS VFS: cifs_mount failed w/return code = -13

Leave a Reply