I’ve tried several ways to automatically mount SMB shares on macOS. This is my current approach; I’ve used it on Sequoia, Tahoe, and Golden Gate. Test it with your own server before relying on it.

SMB shares folders over a network. We’ll use autofs, macOS’s on-demand mounting service, to connect a local folder to a remote share when an application accesses it.

You’ll need Mac administrator access, a network connection to the server, and a server account permitted to use the share. Replace the fictional server nas.example.com, share Vault, and Mac user example throughout.

Check the connection in Finder

In Finder, press Command-K to open Connect to Server, then enter:

smb://nas.example.com/Vault

Sign in and open a known file. If that fails, fix the connection or permissions first; Apple’s server connection guide can help.

For mounting only when you sign in, a login item may be enough. Continue below for on-demand access at a fixed path.

1. Choose a local folder

The local folder is the mount point: where remote files appear. We’ll use /Users/example/Archive; the local and remote folder names can differ.

In Terminal, run whoami to find your Mac account name. Replace example with it in every path, then create the folder:

mkdir -p /Users/example/Archive

Use an empty folder: mounting hides existing local contents. On a shared Mac, check access to the mounted files too; protecting the password file alone does not make them private.

2. Create auto_smb, the share map

I call this map /etc/auto_smb because I like to separate mounts by service type. The filename is arbitrary; if you choose another, use that name in /etc/auto_master too.

The map is a text file connecting local paths to remote shares. If it already exists, make a securely protected backup and preserve its entries.

Create it if needed, restrict it to root (the system administrator account), and open it in vim. sudo asks for your Mac password, not the server password:

sudo touch /etc/auto_smb
sudo chown root:wheel /etc/auto_smb
sudo chmod 600 /etc/auto_smb
sudo vim /etc/auto_smb

The entry below stores the server password in the file. Encoding is not encryption. Use a dedicated, limited-access server account and protect backups. If storing a password is unacceptable, stop here and use a login item or get help with another authentication method.

In vim, press i to edit. Add this as one line in the file, not as a Terminal command:

/Users/example/Archive -fstype=smb,nosuid ://NAS_USER:[email protected]/Vault

Replace NAS_USER and ENCODED_PASSWORD with the server account and password. Percent-encode special characters within the username, password, and share name: for example, space → %20, @ → %40, $ → %24, & → %26, and % → %25. Keep the separators unchanged. Never submit a real password to an online encoder.

Keep the completed line out of shell history, Git, screenshots, and logs. A saved Finder login does not establish that autofs can authenticate unattended.

-fstype=smb selects SMB; nosuid prevents files from granting privileges through set-ID permission bits. Keep the colon before // for the automounter’s parser. Press Escape, type :wq, and press Enter to save and quit.

3. Register auto_smb in auto_master

/etc/auto_master tells autofs which maps to load. It must reference auto_smb for these mounts to work.

Back it up before editing. If prompted to overwrite, answer n and rerun with an unused backup filename before continuing:

sudo cp -ip /etc/auto_master /etc/auto_master.before-smb

Once the backup succeeds, open the master map:

sudo vim /etc/auto_master

Add this line once, leaving the existing entries intact:

/- auto_smb

/- tells macOS that this map uses full paths; auto_smb resolves to /etc/auto_smb. Leave the stock /- -static entry intact, then save and quit vim.

4. Reload and test

Reload the maps:

sudo automount -c

automount -c updates the on-demand mount points and cached map data. Accessing the folder then connects the share:

ls /Users/example/Archive

You should see the remote share’s contents. Check the mount table as well:

mount | grep -F ' on /Users/example/Archive ('

Look for smbfs with the expected server and share; an autofs entry alone is not a connected share. Open a known file through this path. Test again after reboot and sleep/wake before relying on it unattended.

After every macOS update

macOS updates can overwrite /etc/auto_master, removing the /- auto_smb line. This has been reported even after a minor Catalina update. Check after every update.

Open the master map after the update:

sudo vim /etc/auto_master

Restore /- auto_smb once if missing, preserve the rest of the updated file, and confirm /etc/auto_smb still exists. Save, then reload:

sudo automount -c

Repeat the file-access check. Reloading alone cannot restore a missing map reference.

If the share stops working

If Finder also fails, check the server and network. If only this path fails, recheck both map files and the server credentials.

A stale SMB session can survive sleep or a network change. Save your work, close applications using the share, and verify its exact path and SMB source in the mount table before unmounting:

sudo umount /Users/example/Archive

Only if that succeeds, refresh the maps and try the path again:

sudo automount -c
ls /Users/example/Archive

If the mount is busy, close the application holding it. Do not force-unmount: files may have pending writes.

Automating recovery with mount-watchdog

Shares still stop working from time to time, especially after sleep or a network change. That’s why I built and open-sourced mount-watchdog. It checks mount state and server reachability, and can request a normal unmount and map refresh without browsing files or force-unmounting.

mount-watchdog

Start with the setup guide. mount-watchdog expects /etc/auto_smb and paths shaped like /Users/example/Archive, and validates the whole map against its supported configuration.

The next access attempts to reconnect. Its checks do not prove files are readable, and it cannot repair credentials or a missing auto_master entry.