How to Use macOS AutoFS for Automounting Network Shares on Demand

The Flaws of Login Items and Fstab

In macOS environments, connecting to corporate file servers (SMB or NFS shares) is often a clumsy process. The traditional graphical method involves mapping the drive in Finder and dragging it into the user’s “Login Items.” While this works initially, it is incredibly fragile. If the user boots their Mac while away from the office Wi-Fi, macOS will throw multiple annoying error dialogs stating “There was a problem connecting to the server.” Worse, if the Wi-Fi drops temporarily, the share disconnects and does not automatically remount.

For more advanced users, modifying the /etc/fstab file is the standard UNIX approach. However, macOS deprecates heavy reliance on fstab for network volumes because it attempts to mount the drives during the boot sequence, blocking system processes if the network is unavailable.

The definitive, Apple-supported solution for enterprise network shares is AutoFS (the automounter daemon). AutoFS monitors specific local directories. It does not mount the network share when the Mac boots. Instead, the exact moment a user (or an application) attempts to access the directory, AutoFS intercepts the request, instantly mounts the SMB share in the background, serves the files, and gracefully unmounts the share after a period of inactivity.

Step 1: Understanding the AutoFS Architecture

AutoFS relies on two primary configuration files:

  1. /etc/auto_master: The master map file. It defines the root mount points and points the daemon to the specific map files that control them.
  2. Map Files (e.g., /etc/auto_smb): Custom text files that define the actual remote server paths and mount credentials.

By default, macOS uses AutoFS for the /net and /home directories, but administrators can easily create custom mount points.

Step 2: Configuring the Master Map

Open the Terminal and edit the master map file with root privileges:

sudo nano /etc/auto_master

You will see the default Apple mappings. Add a new line at the bottom to define a custom mount directory (e.g., /System/Volumes/Data/Mounts) and point it to a new map file we are about to create (auto_smb).

#
# Automounter master map
#
+auto_master            # Use directory service
/net                    -hosts          -nobrowse,hidefromfinder,nosuid
/home                   auto_home       -nobrowse,hidefromfinder
/Network/Servers        -fstab
/-                      -static
/System/Volumes/Data/Mounts   auto_smb

Note: Since macOS Catalina introduced the Read-Only System Volume, you cannot create custom directories directly at the root /. You must use the writable Data volume path or a directory within the user’s home folder.

Step 3: Creating the Custom Map File

Now, create the auto_smb map file that defines exactly which server to mount.

sudo nano /etc/auto_smb

The syntax for this file is: [Local Directory Name] [Mount Options] [Remote Server URL].

If you want to mount a corporate share located at smb://fs01.company.local/Marketing to the local directory /System/Volumes/Data/Mounts/MarketingData, add the following line:

MarketingData   -fstype=smbfs,soft,noatime   ://fs01.company.local/Marketing

The soft option is critical. It ensures that if the server crashes, the Mac’s Finder will eventually time out and return an error, rather than hanging indefinitely (which happens with hard mounts).

Step 4: Handling Authentication (Credentials)

If the SMB share requires a username and password, you cannot hardcode them into the map file without exposing them in plaintext. AutoFS relies on the macOS Keychain or URL credentials, but for a system-level mount, the most reliable method is to specify a credentials file or embed them securely in the URL (not recommended for production).

For domain-joined Macs utilizing Kerberos (Active Directory), the AutoFS daemon will automatically use the logged-in user’s Kerberos ticket to authenticate against the SMB server transparently, requiring zero credential configuration in the map file.

If you must use local credentials, you can embed them in the URL (ensure the file permissions on auto_smb are restricted to root):

MarketingData   -fstype=smbfs,soft   ://username:[email protected]/Marketing

Step 5: Reloading and Testing the Automounter

Once both files are saved, you must instruct the autofsd daemon to flush its cache and read the new configuration.

sudo automount -vc

The output should verify that the new mount point was created:

automount: /System/Volumes/Data/Mounts updated
automount: /net updated
automount: /home updated

Now, test the magic of AutoFS. Do not map a drive. Do not run a mount command. Simply use the ls command to view the contents of the local directory you defined:

ls /System/Volumes/Data/Mounts/MarketingData

The moment you hit Enter, the terminal will pause for a fraction of a second as AutoFS intercepts the request, negotiates the SMB connection, mounts the drive, and returns the file list. If you open Finder and navigate to that folder, the files will be fully accessible.

If you close all applications accessing that folder and wait a few minutes, AutoFS will silently unmount the drive to conserve network resources.

Conclusion

By migrating from brittle Login Items to the native AutoFS daemon, macOS system administrators can provide a seamless, persistent network storage experience. AutoFS ensures that network drives are instantly available the exact moment a user clicks a folder, and gracefully disconnects when the network is unavailable, completely eliminating the frustration of dropped connections and error dialogs.

RELATED POSTS

  • How to Use Mac Automator to Batch Rename Files
  • How to Find the Serial Number of Your Mac from the Terminal
  • How to Use the macOS Migration Assistant to Transfer Data Safely
  • How to Use macOS Network Utility Command Line Alternatives for Network Diagnostics
  • How to Use the macOS pkgutil Command to Inspect Installer Packages
  • Get the best tech tips delivered straight to your inbox.

    Join thousands of readers mastering Apple, Google, Microsoft, and Linux.