Creating a User with niload
The niload utility understands the flat file format used by /etc/passwd (which is name:password:uid:gid:class:change:expire:gecos:home_dir:shell). See the passwd(5) manpage for a description of each field. To add a new user, create a file that adheres to that format and load it with niload. You can use a here document rather than a separate file. This example creates a user for Ernest Rothman with a UID of 701 and membership in the group numbered 701, which you’ll create next:
$sudo niload passwd . <<EOF>rothman:*:701:701::0:0:Ernest Rothman:/Users/rothman:/bin/bash>EOF
Next, create a group with the same name as the new user and a GID that matches his UID (as of Mac OS X 10.3, users are given their own groups):
$sudo niload group . <<EOF>rothman:*:701:>EOF
As you can see from the example, we set the user’s password field to *, which disables logins for that account. To set the password, we’ll use the passwd command:
$ sudo passwd rothman
Changing password for rothman.
New password: ********
Retype new password: ********If you niload a user that already exists, that user’s entry will be updated with the new information. Before the user can log in, you must create his home directory (see "Creating a User’s Home Directory,” later in this chapter).
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access