At work, we have a bunch of computers running linux and hosting disks that are shared using NFS. Of late, many people have been switching to Macs as their primary computer. Usually, they then just ssh into one of the linux machines and work as before. However, now I think they’d like to be able to stay on their Mac and still access the files in linux. Macs are unix-based, so mounting NFS drives isn’t that much of a problem. However, the default user ID and group ID used on the Mac does not match up with our uids and gids in linux. The default (first) user on a mac, is give UserId = 501 and GroupID = 20. This group id corresponds to the group named staff. I wanted to change these ids so they match up with the ids we use in linux. Then, when the user creates a file on an NFS drive, they’ll have the correct owner and group. How to do this? The dscl command on the mac is the one to use.
First, I created a second administrator account on my computer and logged in as that one. I didn’t try it, but I don’t think that you should change the uid and gid of the user that you’re currently logged in as. So I made a generic admin account, logged in as that and then ran the following.
Find out what your current settings are:
yo:~ $ sudo dscl localhost -read /Local/Default/Users/maryh PrimaryGroupID UniqueID UserShell
This is my account on my laptop. Say I wanted to change things to match the username and account on our linux systems. On those, my uid = 1170 and my default group is “support” with gid = 2002.
First, I’ll create the support group.
yo:~ $ sudo dscl localhost -create /Local/Default/Groups/support gid 2002
Next, I’ll change my PrimaryGroupID to this new group.
yo:~ $ sudo dscl localhost -change /Local/Default/Users/maryh PrimaryGroupID 20 2002
Lastly, I’ll change my UniqueID.
yo:~ $ sudo dscl localhost -change /Local/Default/Users/maryh UniqueID 501 1170
The final thing that I need to do is to change the ownership of all my files in /Users/maryh because they’re still owned by uid=501 and gid=20.
yo:~ $ sudo chown -R maryh:support /Users/maryh
One other command that might be needed is to add users to a different group. Say there was another user on my laptop, arthur and I wanted him to be in the support group as well. I’d run this:
yo:~ $ sudo dscl localhost -append /Local/Default/Groups/support GroupMembership arthur
Here we want to use append because if we used create again, we’d overwrite the original group.
I want to use the automounter to automatically mount disks as needed. I could then open a terminal and cd /cdf/s1 and if /cdf/s1 wasn’t mounted, it would automatically be done. The first file that I’ll set up is in /etc/auto_master. I’ve added the following:
# Automounter master map
+auto_master # Use directory service
/net -hosts -nobrowse,hidefromfinder,nosuid
/home auto_home -nobrowse,hidefromfinder
# MH Additions
/cdf /etc/auto.cdf intr,nodev
/psec /etc/auto.psec intr,nodev
Basically, this says for any mounts under /cdf, the info is in /etc/auto.cdf and for any under /psec, the info is in /etc/auto.psec.
Here’s a bit of what’s in the /etc/auto.psec file.
# Directory Location
This just says that to mount /psec/home, the disk is on the computer called psec. And for /psec/data1, the disk is on psec2.
The last thing that I had to do was to change the AUTOMOUNTD_MNTOPTS option in /etc/autofs.conf. Mine now looks like this:
I just had to add resvport because we have some very old linux servers that use a reserved port for NFS.
Then, I just restarted the automounter and we were all set.
yo:~ $ sudo automount -vc
Note: If you get an “Operation not permitted” error when you try to change to an automounted directory, reboot the computer.