Skip to content

Instantly share code, notes, and snippets.

@rudelm rudelm/
Last active Jan 19, 2020

What would you like to do?
Use autofs on Mac OS X to mount network shares automatically during access

Autofs on Mac OS X

With autofs you can easily mount network volumes upon first access to the folder where you want to mount the volume. Autofs is available for many OS and is preinstalled on Mac OS X so I show you how I mounted my iTunes library folder using this method.

Prepare autofs to use a separate configuration file

autofs needs to be configured so that it knows where to gets its configuration. Edit the file '/etc/auto_master' and add the last line:

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

This will tell autofs to look for a file in the '/etc' folder with name 'auto_smb'. In this case I want to create a configuration for automatically mount SMB volumes. You are free to choose a different name and can also use afp/cifs/nfs etc.

Content of the configuration file

Normally Mac OS X tries to mount network shares into the '/Volumes' folder. This is the default folder for all mounted shares on a mac. However, if you try to directly mount into this folder, autofs will fail. You just add a '/../' in front of your desired mount path and Mac OS X will even accept the Volumes folder. However, some Mac OS Version doesn't like this so I switched over to use my own folder named '/mount'.

If you want to configure AFP, do it like this:

So add this line to '/etc/auto_afp':

/../Volumes/music	-fstype=afp,rw afp://ip-address:/music

Mac OS X is clever enough to lookup the username and password from the Mac keychain so there's no need to add the username and password in clear text to the configuration file.

If you want to configure SMB, do it like this:

Add this line to '/etc/auto_smb':

/mount/music    -fstype=smbfs,soft,noowners,nosuid,rw ://username:password@ip-address:/music

Unfortunately you will need to add the user and password to the resource :( You can try to lock it down further using the Mac OS permissions but that won't help when the attackers user got admin rights as well.

Access the folder and see autofs in action

You now need to restart the autofs service with the command 'sudo automount -cv'. If you now type mount, you'll see a listing of currently mounted volumes. Your desired volume shouldn't be mounted, so unmount it with 'sudo umount /Volumes/volumename' or 'sudo umount /mount/music' before we continue.

You can now switch to '/Volumes/music' or '/mount/music' folder or let it list on the terminal. Once you do that autofs will automatically try to mount the desired volume into this folder.

See an example and explanation in action

Visit my blog post where I explain this gist a little bit more in detail.


This comment has been minimized.

Copy link

anvena commented Jan 19, 2017


Thank you for good examples. Would you be able to provide with example how to configure nfs for Mac Os Sierra?


This comment has been minimized.

Copy link

arontx commented Feb 23, 2017

This does not work as the share is mounted root only


This comment has been minimized.

Copy link

deephack1982 commented Mar 22, 2017

I have the same issue as artonx on MacOSX 10.12.1 that the volumes get mounted at root. Is this a known problem or am I doing something wrong?


This comment has been minimized.

Copy link

uberspeck commented Jan 13, 2018

Anyone have any luck getting this to work in High Sierra? Trying to mount my Synology NAS and nothing I try is working. Is autofs just broken?


This comment has been minimized.

Copy link

caramdache commented Jan 27, 2018

See at the end of the post for a solution on High Sierra


This comment has been minimized.

Copy link

tolsadus commented Feb 23, 2018


This comment has been minimized.

Copy link

turkeyphant commented Dec 27, 2018

I did this. However, it made my system completely unusable.

Finder and alternatives would instantly become unresponsive and have to be killed from Activity Monitor or the terminal. Several other apps wouldn't even start or would crash instantly on boot. No amount of restoring from old Time Machine system backups helped.

Was I doing something completely wrong? I still don't get why a share being unavailable would make the whole system break.


This comment has been minimized.

Copy link

turkeyphant commented Apr 25, 2019

Seems a possible solution is to use "nofail". But does anyone know what "soft,noowners,nosuid,rw" do?


This comment has been minimized.

Copy link

gabeosx commented Nov 8, 2019

Does this work with Catalina? I am not able to get this working.

iMac:Volumes gabe$ sudo automount -cv
automount: /System/Volumes/Data/home updated (/home -> /System/Volumes/Data/home)
automount: /System/Volumes/Data/Music updated (/Music -> /System/Volumes/Data/Music)
automount: /System/Volumes/Data/Video updated (/Video -> /System/Volumes/Data/Video)
automount: no unmounts
iMac:Volumes gabe$ cd /Video
-bash: cd: /Video: No such file or directory
iMac:Volumes gabe$ cd /System/Volumes/Data/Music/
-bash: cd: /System/Volumes/Data/Music/: No such file or directory

I also do not see any authentication activity on the NAS, so I am skeptical that it is even trying to mount the drive


This comment has been minimized.

Copy link
Owner Author

rudelm commented Nov 10, 2019

Hi guys, sorry I did not notice that there were so many responses to this gist.

I did not install Catalina yet, since it seems to be too buggy in my opinion.


This comment has been minimized.

Copy link

chadj commented Dec 20, 2019

@gabeosx I just tested this on Catalina and learned that auto mounts seem to have to go in /System/Volumes/Data now.

So your /etc/auto_smb should look like:

/System/Volumes/Data/mount/music -fstype=smbfs,soft,noowners,nosuid,rw ://username:password@ip-address:/music

Once I made that change it worked fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.