Automounting Samba shares in Leopard

Edit 15th November 2007: After a few weeks of use I have found the automount technique described here is a little unreliable not only from the perspective of keeping the mount point active but also for maintaining the correct file permissions. This maybe addressed in future OSX 10.5 updates but for the time being using user-level mounts via Finder or Go -> Connect to Server is more reliable. To automatically mount a volume save the mount point as a Favorite (Go -> Connect to Server -> Add favorite) and then drag this favorite (stored in ~/Library/Favorites) to the Login Items under Account Preferences.


Apple have pleased a number of people by laying to rest the NetInfo Manager in OSX 10.5 'Leopard'. Many of the functions performed by this Registry-like tool have been incorporated into the far tidier Directory Utility tool. Unfortunately whilst this tool includes the ability to define automounted NFS shares the same capability is not provided for Samba. This is a pain because if you have a couple of Samba servers on the network that need to be connected all the time, a good example being a network share for iTunes music.

Fortunately all is not lost as we can still edit the automount configuration files directly so that our Samba shares are always accessible. To start with open up the Terminal application as an administrative user and then use sudo to create a bash shell.

sudo bash (enter)

You will be prompted to enter your administrator password at this point.

We will now create a file entitled auto.smb in the /etc/ directory to hold our server details.

pico /etc/auto.smb (enter)

In this file enter the following line (add more lines for extra servers/shares) 

$Sharename -fstype=smbfs ://$Username:$Password@$Server/$Share

Where:

$Sharename = the name you want to give the mount point
$Username = the user to connect to the server as
$Password = password of the user
$Server = the name of the server (dns/wins entry)
$Share = the name of the share on the server

As this file stores the username and password to the server in plain text set the permissions of the file so that only the root user can read it.

chmod 600 /etc/auto.smb (enter)

Now edit the /etc/auto_master file and append the auto.smb record at the end of the file. The auto_master file controls all the automounts for the system, leave everything about this file alone except for the extra line at the end. 

pico /etc/auto_master (enter)

#
# Automounter master map
#
+auto_master # Use directory service
/net -hosts -nobrowse,nosuid
/home auto_home -nobrowse
/Network/Servers -fstab
/-  -static
/Users/Resources auto.smb

This will tell the automounter to mount the shares defined in the /etc/auto.smb file under the /Users/Resources directory. So for example if auto.smb defined a Music share we would end up with /Users/Resources/Music. Note: You do not have to use /Users/Resources.

With the configuration files in place it is now time to tell the automounter to refresh the settings. Exectute the following command:

automount -vc (enter)

If all goes well you should see the following output from this command:

automount: /net updated
automount: /home updated
automount: /Users/Resources updated
automount: no unmounts

Now you should be able to open the Finder and see a /Users/Resources directory that lists (and magically takes you to) all the network shares you have defined in the auto.smb file.

Hopefully this is only a temporary fix and Apple includes the option to mount Samba as well as NFS shares in Directory Utility. Technically it is not hard to do and the end result would be far tidier.