new user from the terminal?

Posted:
in Genius Bar edited January 2014
I was just wondering, does anyone know of a way to create a user account from the terminal? If I can do this, it's OK if Mac OS X can't use it like normal accounts because the account will only be used via ssh.

Comments

  • Reply 1 of 4
    formerlurkerformerlurker Posts: 2,686member
    Quote:

    Originally posted by Chaos215bar2

    I was just wondering, does anyone know of a way to create a user account from the terminal? If I can do this, it's OK if Mac OS X can't use it like normal accounts because the account will only be used via ssh.



    -Alfred




    I don't think so, but I think you can create one with NetInfo Manager.



    I'd just use the Accounts pane in System Preferences though - any reason you can't do that?
  • Reply 2 of 4
    Yes, this is possible by the Terminal, but it would be a lot easier to do via the System Preferences. niutil is essentially a command-line version of NetInfo Manager. Here's what you need to do:



    1. Find a unique User ID# and short username for your new user. Your UID should be using the 500+ range because anything below that is reserved for the system.



    2. Then you create the user in the NetInfo database and give it some important data with this set of commands. {username} is your new short username (like bsmith), {longname} is your new long username (like Brad Smith), {uid} is the new UID (like 513), and {gid} is the group ID to which the user will belong.



    sudo niutil -create / /users/{username}

    sudo niutil -createprop / /users/{username} sharedDir Public

    sudo niutil -createprop / /users/{username} name {username}

    sudo niutil -createprop / /users/{username} home "/Users/{username}"

    sudo niutil -createprop / /users/{username} passwd "*"

    sudo niutil -createprop / /users/{username} realname "{longname}"

    sudo niutil -createprop / /users/{username} uid {uid}

    sudo niutil -createprop / /users/{username} shell "/bin/bash"

    sudo niutil -createprop / /users/{username} gid {gid}



    3. Now you are prompted for the new user's password by entering the following command:



    sudo passwd {username}



    4. Lastly, you need to set up the user's home directory. If you don't want the English localization, use an appropriate alternative. {usergroup} is the name of the group that matches the {gid} above.



    sudo cp -R /System/Library/User\\ Template/English.lproj /Users/{username}

    sudo chown -R {username}:{usergroup} /Users/{username}



    Hope this helps!
  • Reply 3 of 4
    ipodandimacipodandimac Posts: 3,273member
    Quote:

    Originally posted by Chaos215bar2

    I was just wondering, does anyone know of a way to create a user account from the terminal? If I can do this, it's OK if Mac OS X can't use it like normal accounts because the account will only be used via ssh.



    -Alfred




    as said above, why waste your time?
  • Reply 4 of 4
    dstranathandstranathan Posts: 1,717member
    Quote:

    Originally posted by ipodandimac

    as said above, why waste your time?



    Because you can!
Sign In or Register to comment.