You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

HOW TO Mount a Network Share using the Automount as non-root

So, this bothered me for some time, and I finally figured it out, so I decided to share it with everyone, in case other people have the same problem.


The Problem: Mount a Samba or Windows share on a mac to a specific mount point, have it autoremount when ever it is reachable, and have it automatically reconnect after a reboot, and have the share be accessible by non-root users.


Solution (almost): This should be simple, but there is a bug in Apples autofs which, after a reboot, automounts shares with root privileges only. Here is the solution, almost. This solution still requires you to run a script after login to remount the drives with normal user privileges, rather then root privileges.


So, here we go. First, let's create the automount shares. You can use your favorite method, but here is mine:


1. Open Terminal and run:


sudo nano /etc/auto_master


2. Add the following line to the bottom:


/-     auto_smb


3. Save, exit nano, and create a new file for your samba connections like so:


sudo nano /etc/auto_smb


4. Add the shares you would like to mount, one per line, in this format to the newlly created file:


/Users/username/mount     -fstype=smbfs,soft     ://user:password@server/share


In the above, the username is your mac username, basically path to your home directory. You can mount it any were inside your home directory, It's not necessary to create the actual mount point directory, automount should make it for you. Though, to be safe, you can do so. Just run 'mkdir ~/path/to/mount'. User and password after // is your credentials for the remote samba or windows share.


5. Finally, run automount to mount the new shares:


automount -vc


Once it's all done, you can switch to the directory were the mount points you have chosen are located. Run 'ls -la' to see the list of the mount points. You will likely see something like "Permission denied for 'mount point'" or something like this. You can run 'sudo ls -la' and you will likelly see that the shares are mounted with root privileges. This is a bug. (Thank you Apple, Now FIX THIS!) For now, however, here is a quick fix:


6. Unmount the shares and then remount it like so:


sudo umount /Users/username/mount
cd /Users/username/mount


Make sure you run the 'cd' command as a normal user. What happens is the share is unmounted, and then automounted once you try to change into it. It will remount with proper permissions.


Finally, so that you do not have to do this every time you reboot, create a bash script with commands in step 6, and run it at login. The annoying thing, you'll have to type your password in every time you run that script, to authorize sudo. I tried many other options ways to atomate it, but the trick is, you must run umnount as root, and you have to run the cd command as normal user.


If any one has a better method, please share, I searched and read every article on the subject, and this is the best method I have found so far, but please let me know if you have a better method.


- Bogdan

OS X Mountain Lion (10.8.3)

Posted on Mar 28, 2013 9:40 PM

Reply
Question marked as Top-ranking reply

Posted on Apr 14, 2013 11:24 AM

I had the same issue as you, and solved it slightly neater using AppleScript. The script looks like this (from my memory):


tell application "Finder"

mount volume "cifs://macmini@192.168.1.1/NAS"

end tell


I saved it as an application and set it to run as a login item for the users that needed it. Once you save the password to your keychain it works automatically on login/reboot without the issues of automount.

21 replies

Aug 31, 2015 4:51 AM in response to x0054

AutomounMaker is an easy to use GUI tool (DONATEWARE OS X native Universal Binary) to create scripts that will mount an AFP, FTP, WebDAV(http), NFS or SMB network share.

You can use the script as a Startup Item in your user's session config to automatically mount the given share upon login.

If you use always the same shared volume on your desktop, AutomountMaker is more easy than the classic Connect to Server... proposed by Apple.

Go to http://jm.marino.free.fr/index.php?switch=sw_&title=AutomountMaker

Sep 25, 2016 3:10 AM in response to callehedberg

I have this problem in El Capitan 10.11.6 - it's persisted this long. AutoFS mounts will just randomly re-mount themselves with 'root' permissions. I have got no idea why it does this and can find no information beyond this thread and a couple of others why. Terrible attention to detail by Apple.


Rather than write a continuously-running LaunchDaemon with a shell script, I decided to use a simpler version of the same basic idea that callehedberg suggested. In my case it's a script that I wrote which I put in my root 'crontab'. I've written it in such a way that a user can put all the customisation at the top in variables.


If I had more time or could be bothered, I'd convert them into arguments.


Also is umount doesn't work, it resorts to diskutil to force unmounting, which may be problematic in some situations, such as when the disk is actually being used for something.


Script is below. Also in github - https://github.com/scotartt/shell_scripts/blob/master/fix_mounts.sh


#!/bin/sh

#

# this file should be run by 'root'. put it in your root crontab.

#

# autofsname - the name of the file in /etc/ that is specified in auto_master

# e.g.

# /- auto_nas -nosuid

# then it's 'auto_nas'

#

# mnt_usr - the userid of the user (you) that you want the mounts for

# mnt_pnt - the directory in the user dir where the mounts are

# t_mnt - using $mnt_usr and $mnt_pnt; the full path to the mounts

# mounts - space-separated list of mounts expected in $t_mnt


autofsname=auto_nas

mnt_usr=smcphee

mnt_pnt=Mounts

t_mnt=/Users/${mnt_usr}/${mnt_pnt}

mounts="special media Erato"


# don't change below here unless you know what you are doing with shell scripts.

all_mounts=`/sbin/mount | /usr/bin/grep $t_mnt | /usr/bin/grep -v "map $autofsname on $t_mnt"`

for mt in $mounts;

do

full_mount=${t_mnt}/${mt}

if [[ $all_mounts == *"$full_mount"* ]];

then

# it is mounted, let us see if it mounted by the user.

mm=`/bin/echo "$all_mounts" | /usr/bin/grep $full_mount`

if [[ ! $mm =~ on.$full_mount.*mounted.by.$mnt_usr ]]; then

# echo "it is NOT mounted: $mm"

/usr/bin/sudo /sbin/umount $full_mount

# if resource is busy force unmount with diskutil DANGER

if [ ! $? ]; then /usr/sbin/diskutil unmount force $full_mount; fi

/usr/bin/sudo -u $mnt_usr cd $full_mount

fi

fi

done

HOW TO Mount a Network Share using the Automount as non-root

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.