Create a Permanent SMB Mount in OSX (Updated)

Creating an permanent SMB mount in OSX is not so easy. Maybe some day Apple will make it a little bit easier, but if this is something you’re looking to do, check out the solutions below. If you have any tips, make sure to share it in the comments!

There’s a few options for creating a permanent mount in OSX so, hopefully, one of them will give you the solution. Mavericks users, please use Option 4!

Option 1

The first option is to modify the /etc/auto_master (sudo vi /etc/auto_master) file and add the following line:

/- auto_smb -nosuid

Then, I created an /etc/auto_smb (sudo vi /etc/auto_smb) file that contained the following:

/Volumes/mount_point -fstype=smbfs,soft ://user:pass@smbserver/share

Next, run the following command to give the /etc/auto_smb the proper access permissions:

sudo chmod 600 /etc/auto_smb

Finally, update your settings:

sudo automount -vc
Authenticating Through Active Directory

If you need to go through Active Directory to authenticate, use the following syntax in your /etc/auto_smb file:

/Volumes/mount_point -fstype=smbfs,soft ://DOMAIN\;user:pass@smbserver/share

Note that you’ll have to escape the semicolon (;). Also, if you’re connecting to a hidden share (i.e. a $ share), you’ll need to escape that too:

/Volumes/mount_point -fstype=smbfs,soft ://DOMAIN\;user:pass@smbserver/share\$

A few notes:

  • The soft parameter specifies OSX to not halt on failure to connect to the SMB server during boot.
  • When entering the password, it’s better to URL encode it as some special characters will cause the automount to fail silently.
  • nosuid parameter in the /etc/auto_master file prevents OSX from mounting the resource as readonly by root (see update below!).

Option 2

The second option is the vifs command. Again using the terminal type in sudo vifs and then insert the following line:

smbserver:/share /Volumes/mount_point url automounted,soft,url==cifs://user:pass@smbserver/share

Then run sudo automount -vc and then cd to your mount point and it should connect.

Option 3

This option is courtesy of a Guest commenter (thanks, whoever you are!):

  1. Connect to your network drive (finder > go > connect to server)
  2. Enter the infos for your login to your network drive and tick the ‘remember in keychain’
  3. Open system settings > users > login items
  4. Drag the icon for your network drive from your desktop to the startup items.

If you use this option, make sure you read my comment below.

Option 4 (Mavericks users)

Modify the /etc/auto_master (sudo vi /etc/auto_master) file and add the following line:

/- auto_smb -nosuid

Create a folder on your system to place your mount in:

sudo mkdir /mnt

Create an /etc/auto_smb (sudo vi /etc/auto_smb) file that contains the following:

/mnt/mount_point -fstype=smbfs,soft ://user:pass@smbserver/share

Next, run the following command to give the /etc/auto_smb the proper access permissions:

sudo chmod 600 /etc/auto_smb

Finally, update your settings:

sudo automount -vc
Authenticating Through Active Directory

If you need to go through Active Directory to authenticate, use the following syntax in your /etc/auto_smb file:

/mnt/mount_point -fstype=smbfs,soft ://DOMAIN\;user:pass@smbserver/share

Note that you’ll have to escape the semicolon (;). Also, if you’re connecting to a hidden share (i.e. a $ share), you’ll need to escape that too:

/mnt/mount_point -fstype=smbfs,soft ://DOMAIN\;user:pass@smbserver/share\$

A few notes:

  • The soft parameter specifies OSX to not halt on failure to connect to the SMB server during boot.
  • When entering the password, it’s better to URL encode it as some special characters will cause the automount to fail silently.
  • nosuid parameter in the /etc/auto_master file prevents OSX from mounting the resource as readonly by root (see update below!).

Update 04-26-2013: As a commenter indicated below, you may want to chmod the auto_smb file to 600. If you’ve run into the issue where root is the only one allowed to read/write to the mount, doing this will set the necessary permissions for the SMB share (particularly when your system reboots). I will verify this when I get the chance. Thanks Jeremy!

Update 07-01-2013: Ok, well looked into this more and I think I finally found a solution to the issue where root is the only one allowed to read/write to the mount. I first tried Jeremy’s recommendation, however, his suggestion did NOT work for me. It’s important to note that you should still chmod the auto_smb file to 600 so that the file is only readable by root. This provides an extra security layer especially if you’re specifying a password to access your SMB mount. Anyway, I really wanted to figure out a solution, so I did a little bit more research and found this link. What one user recommends is to use the -nosuid option in your auto_master file:

/- auto_smb -nosuid

Now, after you save the file, make sure you run:

sudo automount -vc

The last command is required for this to work. Once I did that and I rebooted, the SMB shares were immediately available (i.e. they were NOT owned by root)!

Update 01-13-2014: Looks like Apple has done some changes to Mavericks that affect the /Volumes folder, which will directly affect users attempting to use the above instructions. According to Alex R, Mavericks won’t allow any other folders in the /Volumes folder, for reasons unknown. The fix is to simply use a mount point at a different location. In Alex R’s case, instead of using /Volumes, try using /mnt instead. I have yet to verify this as I haven’t installed Mavericks yet but it sure looks like Alex R figured it out. Thanks Alex R!

See blogspot.com

  • Doc. Caliban

    Hello,

    Thank you for this!

    I am having an issue due to my share name having a space in it. I have tried replacing the space with %20 but it will still not mount. Any ideas?

    • Try escaping the space by putting a backslash in front of it, for example:

      /mount_point -fstype=smbfs,soft ://user:pass@smbserver/share name

  • Stompel

    Hi

    I know i m late heheehe.
    i tried the first option.
    It mounts but doesnt show me any of my data?
    My automaster look slike this at the mo:

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

    /hosts -hosts -nobrowse,hidefromfinder,nosuid

    Is there something wrong here?

    • Hmm I don’t see anything wrong here, but I suspect it’s something in your auto_smb file.

  • Jeremy

    I can confirm the auto_smb method works in mountain lion however I ran into an issue preventing deletion of files or creation of folders after the initial reboot. I found on another site where they set permissions on auto_smb to 600 and this appeared to be the missing link in the setup for my purposes.

  • crocell

    “Maybe some day Apple will make it a little bit easier”

    Why dont you try this :

    – connect to your network drive (finder > go > connect to server)

    – enter the infos for your login to your network drive and tick the ‘remember in keychain’

    – open system settings > users > login items

    – drag the icon for your network drive from your desktop to the startup items.

    • Hi, thank you for the suggestion! Note, however, the main issue with this is if the resource isn’t immediately available when your system boots, an error will pop up indicating that the resource cannot be connected to, at which point, there’s no option to attempt to reconnect to the resource (i.e. you’re dead in the water again). This scenario will particularly be evident with wireless-only computers such as the Macbook Pro Retina. However, I think this will work for a bulk of the users out there, particularly those with wired connections.

      With the automount method, errors are done silently and if the mount is not connected, when an application attempts to write to the mount, it will automatically be mounted.

      Again, thanks for sharing!

  • Fgaumond

    Hi, that’s sounds like a great solution, but I’m not able to access my drives, it says “Too many users”, but when I use “connect to server” with the same credentials and network path it worked, any ideas ?

    Thanks

    • Hi! You may want to ensure you URL encode (http://meyerweb.com/eric/tools/dencoder/) your password, especially if you have special characters in it. I ran into that error before and the “Too many users” problem was because my password wasn’t URL encoded. Let us know how it goes!

      • Fgaumond

        You are totally right ! I needed to encode my password. I should have noticed…

        Really great solution !

        I hope that Apple will improve that in future releases, otherwise we are all glad that you are here to help us figure that out !

        Thanks a lot for your solution, I’ve lost a lot of time trying to figure out how to acheive that.

      • Fgaumond

        The only weird thing, is that my applications (like Word or Excel) are not able to access the drives (either in read or write). But I can read and write in the finder..

        I’ve done the sudo 600 on the auto_smb file.

        Anyone has experience that kind of behavour ?

        • Hmm I have not experienced that. Do you access the file via the mount point? For example, I use an IDE (PHP Storm) to modify my development files. I access the mount point in the Volumes folder (i.e. /Volumes/MYSERVER/c/inetpub). Is this how you’re connecting to your file from Excel?

          • Fgaumond

            It seams working fine now… I didn’t do anything, but it’s working.. Maybe a reboot does it.

            Thanks again man, you’re a genius !

    • I was seeing this same error because my password was not url encoded properly. Once I url encoded my password this started working.

  • Stephen Silbert

    I’m using the option 1. Though I specify -nosuid the smb share is still owned by root:wheel. And it’s mounted (autofs, nosuid, auto mounted, nobrowse). The “nobrowse” is a real deal breaker! I’ve played with mount and mount_smbfs and seem to get the same results. If I login to the share using the finder it works fine but dragging the share into login items (option 3 above) doesn’t work as you describe for these wireless laptops. I’m beginning to suspect the configuration of the share but any help is welcome.

    • Hmm did you try:

      sudo chmod 600 /etc/auto_smb
      sudo automount -vc

      Then try rebooting?

      • Stephen Silbert

        Yup. I’m going to try a different smb share and see what happens. Thanks for the quick reply.

  • MC

    I was delighted to find this several months ago to automagically allow Crashplan to backup my Mac to a NAS drive at home, but alas…

    It would seem that OS 10.9 Mavericks includes updates that Apple made to the networking stack which results in Option 1 failing to work now. Based on some other research, I’ve tried shifting from smb to cifs and some other things, but the drive still reports as “mountpoint unavailable” when I automount is run. Bummer.

    If anyone else ferrets out an update to this, I would appreciate it!

    • That’s unfortunate. I was hoping this wouldn’t break in Mavericks, but thank you for the heads up. I’ll be installing Mavericks soon; I’ll need to upgrade Parallels first. Maybe someone will come up with a fix by then!

      • Regrettably this is happening for me too on OS X 10.9.1 (latest)… I’d just stumbled across your blog and thought I’d found a wonderful solution! Will post back if I somehow manage to resolve this.

        • Just purchased Parallels 9 so I’ll be making the upgrade to OSX 10.9 sometime this week. Hopefully we’ll figure it out :-).

      • Okay, so there’s some really informative stuff on this subject over at
        https://discussions.apple.com/message/23650970#23650970. Basically, it turns out to be a bad idea to use /Volumes for automount points, since it’s Finder’s own mount point, which it manages as it sees fit. Indeed, you should find that if you mkdir in /Volumes before running automount, it works, but then the directory disappears after rebooting, which is no surprise really if Finder considers itself the owner and manager of the /Volumes dir.

        Now, the solution for me was creating a /mnt root directory and using that; i.e. in my auto_smb file having something like:

        /mnt/Home-Share-A -fstype=smbfs,soft smb://admin@Home-Share-A/

        Since /mnt is not expected to be used by anything else on OS X, the mounting and unmounting seems to work perfectly there, and the mountpoint dir never gets deleted.

        Hope that helps!

  • I hate admitting it, but I have wandered out of my area of knowledge and have to ask for an assist. I can access terminal but actually doing any of the actions (particularly for Mavericks, option 4) is way beyond my comfort zone. Some simple (aka step-by-step) instructions would be tremendously appreciated!

    • Hi Michael,

      Have you ever worked within the terminal before? All of the commands in Option 4 will need to be done in the Terminal App.

      • I have used the terminal… but only by following step-by-step directions (think “Terminal for Dummies”).
        That being said, I believe that I have gotten to the end of the instructions in step 4. After entering the “sudo automount -vc” command, I received the following:
        automount: /net updated
        automount: /home updated
        automount: no unmounts

        Now, if that is all what’s meant to be… what next?

        • Hi Michael,

          That list should also include your SMB mount(s). Did you do the following:

          1. Open a terminal and type sudo vi /etc/auto_master

          2. Go to the end of the file by using the arrow keys.

          3. Type the letter i. At this point, you’re in “INSERT” mode, which should be indicated at the bottom of the terminal window.

          4. Insert a new line with /- auto_smb -nosuid

          5. Hit the “esc” key and then type :wq

          6. Now you’re going to create the auto_smb file, so type in sudo mkdir /mnt/share

          7. Now sudo vi /etc/auto_smb

          8. Type the letter i again, then type /mnt/share -fstype=smbfs,soft ://user:pass@smbserver/share

          9. Hit the “esc” key and then type :wq

          10. Lastly, sudo automount -vc

          Hope this helps,

          Ron

  • Martin Jönsson

    So, I’ve done the mount according to the Mavericks instructions, but I’m having some problems. For one, the mount seems to automatically mount as root only, meaning I have to do “sudo umount” and then navigate to it, in the terminal, as a user before I can even access it. Also, it fails to automount when iTunes is trying to access the library files I have stored on it. Instead, iTunes simply fails, reverts to the default library location and complains when it can’t find any files. (I have my library files locally on my computer, and the “media” storage on my NAS.)

    This solution seems to work only sometimes, and especially breaks on reboots. It works perfectly when merely sleeping the computer, however, as I never have any problems reconnecting once I’ve fixed all the errors from bootup.

    Any ideas?

    • Not sure why it would break after boot/reboot. What do you have to do in order to get it to work after you reboot? Are you on wireless?

      • Martin Jönsson

        I am on wifi, yes. I haven’t done any rigorous testing, but it seems I have to unmount it as root, then do a “cd” into the directory as a user, in order for the share to mount properly.

        I’ve used a similar method before, using automount but with AFP instead. I’ve reverted to that, and I’m going to do some testing. Hopefully that will be more stable.

        • Understood. Maybe it has something to do with OSX attempting to mount before a wifi connection is established. And if you haven’t already tried, make sure you have the -nosuid flag in your auto_master file and that you created the mount in a directory other than Volumes. Good luck!

  • insttechno

    Thanks Ive been looking for a good way to do this for a while. One note, if you are using /mnt make your mount point folders using mkdir first as well.

    I didnt and for some reason it would list the folder in terminal but not in finder.

    Also to access /mnt easily in finder press command + shift + g then type /mnt and press enter.

    Once there you can drag the mounts to your favourites (Im on OSX Mavericks)

  • insttechno

    Do applications need some sort of specific access? I can write in finder but trying to use a folder in uTorrent says I do not have permissions.

    • insttechno

      EDIT: I’d mapped the drives to /mnt Changing the path to be inside my user directory seems to have fixed the issue.

  • Gustavo Castro

    I am having the same proble as Stephen Silbert below.
    Even using the -nosuid flag, the folder is only accessible by some wierd osx user named _spotlight

    • Hmm still haven’t had the time to look at this and fully test Option 4, unfortunately. My way around it for now is just to unmount. Then, whenever I access the share, it remounts with the proper owner. Hopefully someone would have some better insight.

      • Robin

        Dear Ronald. Here is a thread on Apple’s discussion forums where
        people say there is a bug and propose a workaround using a script and a LaunchDaemon: https://discussions.apple.com/thread/4927134#25321298

        Did you already have a look at that?

        • Interesting, thanks for the link! I haven’t personally tried it as I’m content with performing an unmount, even though it’s fairly inconvenient. Looking at the post, it seems that callehedberg’s option is the best option at the moment. You probably don’t need the sudo -u user cd /Users/user/mount line as it will auto mount when you first access the directory after you login.

          • cluelessness

            do you think that works with vms and unmounting/remounting? I gave up on automount and went the sleepwatcher way when my vmdk on the nas had errors after sleep, but hadn’t tried the umount/mount script

  • Bolla Sandor

    Hi there, I’m struggling to configure smb the way mavericks Apache can write on it. Does anybody met this? I can mount easily via finder connect to folder option, but after that apache denies write access on that folder. Tried with mount_smbfs on terminal but there is no more option (earlier it was -u) to change uid / guid for access permissions.

    r.
    Sandor

  • JJussi

    I mount smb stuff to /Volumes/xxx and to make so that mounting works everytime, I need to write in /etc/auto_smb /../Volumes/xxx

  • Yue

    I believe the trick is the directory /Volumes in Mavericks. If you encountered the permission failure due to the SMB mount point being owned by root with permission 700, please just try to change the mount point to /Volumes/. Then everything might work out.

    Another caveat is that SMB password has to be encoded just like the HTML encoding for those special characters.

    Below is my working configuration in Mavericks:

    ## /etc/auto_master

    /Volumes auto_smb -nosuid

    ## /etc/auto_smb
    share -fstype=smbfs,soft ://:@192.168.1.3/share

  • Waldemar

    Thanks for still replying to this theme.
    I cannot get it running by any chance, just showing a white rectangular in the finder after ‘sudo automount -cv’.

    My auto_master contains:
    /- auto_smb -nosuid
    the auto_smb:
    /Synology/homes -fstype=smbfs,soft ://user:passwd@10.0.0.152/volume1/homes

    When I try in the finder K and type smb://10.0.0.152/homes I will be asked for my credentials and the got the connection immediately (Synology needs the ‘volume1’, I tried it without anyway).
    A NFS connection is working but I´m not happy with the rights management.

    Help is highly appreciated

    • Do you have any special characters in your password? You may have to URL encode your password.

      Your configuration looks correct. You may try to remove the soft option as well and try that out.

      • Waldemar

        Just characters a to z.

        Tried without ‘soft’, no effect. Several reboots, same story.
        I’m using Mavericks 10.9.4

  • Alain Paschoud

    Hi,

    I am using Mavericks and implemented the above solution, including update from 07-01-2013 and 01-13-2014. Initially, this was working and I had my disc auto mounter with user permissions. But some days after, for some unknown reasons, something changed. Now, with the same configuration of auto_smb and auto_master than before, the volume is desperately mounted with only “root” permissions after the login:

    drwx—— 1 root wheel 16384 1 oct 07:12 mount_point

    If then I simply run the command:

    sudo umount /mnt/mount_point

    then, the volume is automatically unmounted and remounted at the same point with user permissions (thanks to the configurations done as described in this article. This proves that my configuration is correct). The result is then:

    drwx—— 1 user wheel 16384 1 oct 07:12 mount_point

    I cannot understand why I first have to run as sudo an unmount command to have the disc mounted as a user, as described in this article, and why I don’t have the disc mounted directly with the user permissions at login. Does somebody have some advices where to look to fix this ?

    Best regards.

    • This has been my same problem. It seems that the fix that used to work, is no longer working. Haven’t had a chance to take a look at this more in-depth so perhaps someone is able to shed some light on this.

      Thanks!

      • cluelessness

        I figured out a fix for this now that seems to be working
        don’t specify login information in auto_smb, then root can’t list it and gets a ‘no locks available’ message. but as myself i can list it and it mounts automatically

        entry then looks like this ( * haven’t tried adding soft yet )

        /mnt/Create -fstype=smbfs ://omv/Create

        or the ip address instead of where i have ‘omv’

        for the user you’re connecting as, create a file
        ~/Library/Preferences/nsmb.conf

        [omv]
        addr=192.168.0.111
        [omv:USERNAME]
        password=PASSWORD
        [omv:USERNAME:Create]
        timout=10

        i changed mine to only be readable by me
        ls -l ~/Library/Preferences/nsmb.conf
        -rw——- 1 me staff 86 Oct 9 11:07 /Users/me/Library/Preferences/nsmb.conf

        more info in ‘man nsmb.conf’

        • Whoa, interesting solution! I’ll try it out and add it to the list of options. Thanks for sharing! So, this will work even after reboot?

          • Benjamin

            i created the nsmb.conf as above (of course with my usernames, sharenames and password) but have no luck. my user only displays a “No locks available”

          • Andrey Zimovnov

            Yep, “man nsmb.conf” on Mavericks 10.9.5 shows that proposed key-value pairs are not allowed. I used Mavericks section of this tutorial. What has worked for me is to comment all lines in /etc/auto_smb file, reboot, then create directories for all my shares using my user_name in /Users/user_name/share_name (check permissions, it should be owned by you), then uncomment lines in /etc/auto_smb and reboot again. It should work by now.

          • Andrey Zimovnov

            Second reboot and it’s gone, so close…

          • Benjamin

            the nsmb.conf workaround sounded quite promising. does it log sometthing somewhere?

          • Benjamin

            Any News on this?

          • cluelessness

            this confirms the man page info of no password from nsmb.conf ( though it also shows they don’t put everything into the man page )
            http://www.opensource.apple.com/source/smb/smb-551/lib/smb/preference.c
            readPreferencesSection is where they parse nsmb.conf, pretty easy to see what they check for.

          • cluelessness

            edit /System/Library/LaunchDaemons/com.apple.smbd.plist
            add 2 entries for arguments -debug and -stdout

          • cluelessness

            This was working that night, but I must have been misled by some transient stored authentication and yeah Andre password isn’t recognized.

            I think i’ve found something that’s working, mavericks, survives reboots and sleep. based off of http://www.bluepiccadilly.com/2012/10/mac-os-x-automatically-connect-network-drive-when-your-computer-starts-or-wakes-sleep and https://discussions.apple.com/thread/4927134 and some other places.

            requires one app, sleepwatcher from http://www.bernhard-baehr.de or macupdate. I installed using brew ( brew install sleepwatcher ), there are guides on how to install and hints.macworld.com recommends it often, so hopefully it’s stable.

            1) make a directory for your own scripts, i use ~/bin
            2) start apple script editor and make a script like below, the delay should be however long it takes your ethernet to wake up and get a link up after sleep. 10 is 10 seconds.[formatting sux so using pastebin]

            connect_smb.scpt ( http://pastebin.com/b69vcBrE )

            ( one block of try/end try per mount )

            eject your network volume in finder, then press the run button to make sure it works ( and get prompted for keychain if it’s new share )

            3) save that as a script in the script directory, for me ~/bin/connect_smb ( actual filename will be connect_smb.scpt )

            4) create 2 plist files in ~/Library/LaunchAgents
            I called mine

            wake.plist ( http://pastebin.com/X02qHGGg )
            login.plist ( http://pastebin.com/8LS76557 )
            * i had full path to a wrapper script in my login plist originally, so not 100% until reboot it works as in the pastebin

            add the plists as services or whatever, they’ll run under your account name and so avoid root mount problems

            launctl load ~/Library/LaunchAgents/wake.plist
            launctl load ~/Library/LaunchAgents/login.plist

            done!

            you could also do the login part by saving the script as an application and adding it to login items.

          • cluelessness

            login.plist doesn’t like path to script as ~/bin/script.scpt ( wake.plist is fine with it )
            had to change it from
            ~/bin/connect_smb.scpt
            to
            /Users/MYUSERNAME/bin/connect_smb.scpt

            so far it’s been working though.

          • cluelessness

            after 10 days with this, it’s pretty good. I added a disk in vmware on an smb mount, and a couple times coming out of sleep had to click dialog from vmware saying a disk operation had problems ‘should it retry’, then it retries and is fine.
            once though when awakening in middle of a defrag on the windows, the disk operation wasn’t fine and i had to reboot the windows vm. no damage to the disk seen by chkdsk but still… Not where i’d like it to be yet.

            enabling these settings in /etc/autofs.conf gets some more info into console logs
            AUTOMOUNT_VERBOSE=TRUE
            AUTOMOUNTD_VERBOSE=TRUE
            AUTOMOUNTD_TRACE=2

            source xcode projects for smb and autofs can be downloaded from https://opensource.apple.com/release/os-x-1095/ by clicking the blue button next to them. I spent a couple hours going through each and don’t *think* there’s anything in autofs to affect the ‘mount as root’ behavior. also didn’t see any way for smbfs to get different passwords, or effective uids

            noticed from that there’s a debug util,
            /System/Library/Extensions/autofs.kext/Contents/Resources/watch_for_automounts
            that gives a not very useful stack trace when automounts happen. for me as root and me as me they were identical except the uid calling it and last value in stack trace was a 2 for me as root and 3 for me as me. think i’d need to run the system in a debug mode to get function names in the stack trace.
            2014 Nov 14 18:51:54 uid=501 pid=11687 ls /mnt/Consume returns 0

            0x7fff91e0e622
            0x7fff9a4d1092
            0x7fff9a4d17b0
            0x108cc2fab
            0x108cc2cac
            0x7fff937225fd
            0x3

            so… now i’m nearly down to trying the mount/unmount script option, just seems like it’ll mess up vmware so i’ll try lowering seconds to 1 in the sleepwatcher script first.

  • Alain Paschoud

    Hi,
    I have an update to my previous post… I upgraded to Yosemite, and the above method (applying Update 07-01-2013) works fine again !

  • Yee-Ting Li

    just wasted like 10 minutes on this: if you can’t get it to mount (and a manual mount_smbfs works for you), then make sure your auto_smb file has a carriage return at the end of it!