This HowTo assumes you can already access a samba share but want to have these shares available automatically when you log into your machine.
AutoFS is a unique utility that allows a user to automatically connect to, mount, and use a samba share when the desired mount point is accessed and disconnects when not in use. It offers some distinct advantages over other methods.
** Unlike the standard fstab method there is no delay in booting the machine if the target server is not present and because of the way it designed there is no delay if the server goes down before you logoff the client.
** It is not gvfs based so it provides further advantages:
-- gvfs has been rewritten and appears to be quite buggy at the moment so AutoFS can be used to replace Gigolo.
-- No gvfs dependency means it can be used in KDE ( It's used in OSX so it's truly cross platform )
-- No gvfs dependency means you can access samba shares in non-gvfs aware applications.
-- You have control over where the share is mounted
[1] Install the following packages:
Code: Select all
sudo apt-get install cifs-utils
sudo apt-get install autofs
/mnt/Samba is the parent folder under which all your samba shares will be mounted and can be set anywhere but it's best to stay away from your home directory and definitely stay away form /media since the system uses that for other things.# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
+auto.master
/mnt/Samba /etc/auto.sambashares --timeout=30 --ghost
/etc/auto.sambashares is where you define how the shares are to be mounted - called the map file.
timeout is the amount of time before an unused share is unmounted.
ghost creates “ghost” versions (empty directories) of all the mount points - mounted or not.
[3] Create a new file which will define the actual mount - the map file:
Code: Select all
gksu gedit /etc/auto.sambashares
[4a] If the share allows guest access you can use one of these variations:
Code: Select all
ShareName -fstype=cifs,rw,uid=1000,iocharset=utf8 ://server/share
ShareName -fstype=cifs,rw,uid=1000,guest,iocharset=utf8 ://server/share
ShareName -fstype=cifs,rw,username=guest,password=xxx,uid=1000,iocharset=utf8 ://server/share
Code: Select all
sudo service autofs restart
[4b] If you require full credentials to access the remote share you can use one of these:
Code: Select all
ShareName -fstype=cifs,rw,username=name,password=secret,uid=1000,iocharset=utf8 ://server/share
ShareName -fstype=cifs,rw,credentials=/home/altair/secret.txt,uid=1000,iocharset=utf8 ://server/share
Code: Select all
username=altair
password=altairspw
[5-Optional] To restrict access to the auto.sambashares files so no one but root can see the username and password you can do this:
Code: Select all
sudo chmod 0600 /etc/auto.sambashares
Code: Select all
chmod 0600 /home/altair/secret.txt
Code: Select all
sudo service autofs restart
*** For all the shares specified in auto.sambashares you do not mount them under Network in your File Manager or "Connect to Server".
*** You access ( and mount ) them by accessing the mount point itself under /mnt/Samba in whatever application you are using.
*** Autofs will create the /mnt/Samba directory and the /mnt/Samba/ShareName mount point by itself based on the files you edited above.
*** The mount will automatically unmount itself after 30 ( based on "--timeout=30" in auto.master ) seconds of non use but you can adjust that to your needs. This is really all transparent to the user since any access will keep it alive.
EXAMPLE: This is an example of a /etc/auto.sambashares file that defines multiple shares on different servers:
Code: Select all
Box1-Downloads -fstype=cifs,rw,uid=1000,iocharset=utf8 ://box1.local/downloads
Box2-Documents -fstype=cifs,rw,uid=1000,iocharset=utf8 ://box2.local/documents
NAS-Test -fstype=cifs,rw,uid=1000,username=name,password=secret,sec=ntlm,iocharset=utf8 ://nas/test
*** The server can be expressed in the normal samba accepted formats, namely:
ip address ( ://192168.0.100/downloads )
mDNS qualified host name which all Linux and OSX machines use ( ://box1.local/downloads )
netbios or hostname alone ( ://box1/downloads )
*** It can accept certain options so in the nas example above I had to add the the old "sec=ntlm" option because the nas won't accept access without it.
More templates contained in this thread:
Multiple concurrent users setup: viewtopic.php?p=766521#p766521
Multiple non-concurrent users setup: viewtopic.php?p=822762#p822762