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)