MacOS – Can an Open Directory (10.8) user’s home directory be changed from the terminal

macososx-serversshterminalwebserver

I'd like to use SFTP/SSH for users (students and faculty) to manage their web content. The default home directory is "/Users//". I'd like to point them to something like "/Users//web" to block access to the other folders that are created in the home directory.

I want to use terminal in order to avoid manually changing the setting for > 400 users. Is this possible?

Best Answer

Yes, it's certainly possible, but you'll need a bit of scripting knowledge to do it entirely. I wish I had a more elegant solution to edit things in place, but here's ham-fisted option if no one has a more surgical option.

I typically use slapcat to dump the current user details to a text file and then process is using perl or whatever other tool you want. Since it's one file, even TextEdit can do a search/replace. By putting the users in a group, you can specify that in slapcat.

At this point, I'd convert that text file into the import format that server app wants - see it's help guide - Server Help: Create a file to import users or groups (or click this after pasting it locally to your Mac help://bookmark='https://help.apple.com/serverapp/mac/2.2/help/index.html?localePath=English.lproj#apd41051F16-D4B7-464F-BD1C-0CBEDF7CA29A')

At this point you could delete the affected records and re-introduce them with the correct home directories.