I'm attempting to create a 'Sharing Only' account in an OS X app.

I've tried code based on examples like these:
Can user accounts be managed via the command line?
What steps are needed to create a new user from the command line on mountain lion?
without success.

From System Preferences -> Users and Groups -> Advanced Options for 'Sharing Only' account:
Home directory: /dev/null
Since /dev/null discards streams directed to it, substitution in place of '/Users/NewUser' into above code doesn't work.

  • /dev/null is a character pseudo device, not a directory.
    – 4ae1e1
    Commented Aug 3, 2015 at 0:37
  • OK. The two links started with something like: dscl / -create /Users/NewUser so I thought this might help; perhaps not. Should I remove the information about /dev/null and replace with: I would like to do the same as this in OS X: Users and Groups -> Add a user account -> New Account = Sharing Only.
    – wyltowyn
    Commented Aug 3, 2015 at 4:48

1 Answer 1


Based on bispymusic's answer to a previous question:


dscl . create /Users/sharinguser    # use whatever account name you want
dscl . create /Users/sharinguser RealName "Sharing-only Account"
dscl . create /Users/sharinguser hint "Password Hint"
dscl . create /Users/sharinguser picture "/Path/To/Picture.png"
dscl . passwd /Users/sharinguser thisistheaccountpassword
dscl . create /Users/sharinguser UniqueID 550    # Pick something unique
dscl . create /Users/sharinguser PrimaryGroupID 20    # Staff group
dscl . create /Users/sharinguser UserShell /usr/bin/false    # No shell access allowed!
dscl . create /Users/sharinguser NFSHomeDirectory /dev/null    # No home directory!

As with the script it's based on, you'll either need to run it with sudo, or prefix each dscl command with sudo. Be sure to adjust the account name, RealName, password, and UniqueID (and probably the hint and picture). Note that the critical attributes to make this a sharing-only account are the UserShell and NFSHomeDirectory attributes -- leave these as I have them.

It's a bit confusing that all of the lines refer to /Users/sharinguser (or whatever account name you choose) despite this not existing in the filesystem -- this is because it doesn't refer to a file path, but to the path to a record in OS X's directory service. The filesystem and OS X directory services both use the same path notation, but actually have very little to do with each other. Thus, the home directory path can be set to /dev/null while the account's path directory service stays normal.

  • Thanks Gordon! Your solution worked and your description is clear. You were correct about me misinterpreting paths. I will seek information on OS X's directory service to gain understanding.
    – wyltowyn
    Commented Aug 3, 2015 at 23:25
  • @wyltowyn if you want to get familiar with the directory service node structure, run dscl without any arguments. It'll put you in an interactive mode where you can explore the directory service system very much like you'd explore the filesystem. You can use cd to move between "directories", ls to list subdirectories and records, and read to list the attributes of a record (analogous to cat or more in the regular shell). When you're done exploring, exit will get you out. Hint: start with cd /Local/Default, then explore from there. Commented Aug 4, 2015 at 5:08
  • Thanks again Gordon! I ran dscl and found a lot of "directories" and records. I can now see the connection between commands I've been using such as 'sharing' and 'dscl' and the directory service.
    – wyltowyn
    Commented Aug 5, 2015 at 5:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .