There are a couple of way to mount Samba shares, but I prefer using "autofs" which can mount them on the fly. Use the autofs daemon to have shares automatically mounted on demand. The netfs service (installed by default in Fedora) is not a daemon and can only mount shares on boot, (it can't mount them on demand).
* Install the “autofs” package:
* Edit /etc/auto.master (the master map file), and comment out all lines (with #). This avoids conflicts with the CDROM (which is handled by Gnome), etc. Save the file.
* Create a new file /etc/auto.cifs, with the contents of:
Code:
#!/bin/bash
# $Id$
# This file must be executable to work! chmod 755!
key="$1"
# 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.
credfile="/etc/auto.smb.$key"
# Note: Use cifs instead of smbfs:
mountopts="-fstype=cifs,noperm,file_mode=0660,dir_mode=0755"
smbclientopts=""
for P in /bin /sbin /usr/bin /usr/sbin
do
if [ -x $P/smbclient ]
then
SMBCLIENT=$P/smbclient
break
fi
done
[ -x $SMBCLIENT ] || exit 1
if [ -e "$credfile" ]
then
mountopts=$mountopts",credentials=$credfile"
smbclientopts="-A "$credfile
else
smbclientopts="-N"
fi
$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 }
'
* Set proper permissions on the file:
Code:
chmod 755 /etc/auto.cifs
* Edit /etc/auto.master, and add this line at the bottom (this makes autofs look for the map file for the server that is requested, and mount it in /mnt):
Code:
/mnt /etc/auto.cifs --timeout=0
* You can change the timeout to a value which will cause volumes to unmount after a period of inactivity (best for shares that go up/down on the network often). But if you are mounting volumes from a server, using a timeout of 0 is usually sufficient.
* Create additional files in /etc/ as: “auto.smb.servername” for each server you wish to connect to, where the the servername is the hostname that contains the share you are connecting to. The contents of each of these files would be:
Code:
username=yourusername
password=yourpassword
* To protect the password:
Code:
chmod 400 /etc/auto.smb.servername
* Add each servername from the above line to /etc/hosts so that autofs can find the host.
* Make sure “autofs” is set to start automatically on startup, and that “netfs” is NOT set to start up automatically (using the "ntsysv" utility as root).
* Now when you access the path of : /mnt/servername, it will appear and all of the shares will be located underneath it (i.e. /mnt/servername/share1), etc. Autofs will scan the server and add all available shares automatically (per the script used as auto.cifs).
One caveat: autofs will only mount the volumes when a request is made to the mount folder that it is pointed to, i.e. /mnt/servername in the example above. I made a static link on my Desktop that points to the shares, (/mnt/servername/share1, /mnt/servername/share2, etc.), which does the trick.