Manage users and groups

From AwkwardTV
Jump to: navigation, search

Users and groups are managed via

  • the niutil command which allows to examine and manipulate NetInfo database items and
  • the dscl command which allows to examine and manipulate Open Directory database items.

Using niutil

Examine users and groups

The groups list can be examined with:

niutil -list . /groups

The frontrow group's properties can be examined with:

niutil -read . /groups/frontrow

The users list can be examined with:

niutil -list . /users

The frontrow user's properties can be examined with:

niutil -read . /users/frontrow

Modify users and groups

The OS X user tools provides the scripts

  • groupadd
  • groupdel
  • useradd
  • userdel

with the functonality of the corresponding Linux commands

To use these scripts, you will have to copy nidump to the AppleTV. It can be found on the Darwin x86 iso.

With nidump, you can examine users and groups:

nidump group .
nidump passwd .

Add a group

The effect of the command

groupadd -g 100 users

is given by the following code:

group='users'
group_id=100
niutil -create . /groups/$group
niutil -createprop . /groups/$group name $group
niutil -createprop . /groups/$group gid $group_id
niutil -createprop . /groups/$group passwd \*

Delete a group

The effect of the command

groupdel users

is given by the following code:

group='users'
niutil -destroy . /groups/$group

Add an user

The effect of the command

useradd -m fred

is given by the following code:

user='fred'
user_id=500
group_id=100
group_name="$user"
home_directory="/Users/$user"
real_name="$user"
login_shell=`which bash`
niutil -create . /users/$user
niutil -createprop . /users/$user uid $user_id
niutil -createprop . /users/$user name "$user"
niutil -create . /groups/$group_name
niutil -createprop . /groups/$group_name name $group_name
niutil -createprop . /groups/$group_name gid $group_id
niutil -createprop . /groups/$group_name passwd \*
niutil -createprop . /groups/$group_name users $user
mkdir -p $home_directory
chown $user:$group_name $home_directory
niutil -createprop . /users/$user home $home_directory
niutil -createprop . /users/$user realname $realname
niutil -createprop . /users/$user shell $login_shell

I didn't manage to provide a password with the help of niutil and passwd. But it worked with:

dscl / -passwd /Users/$user $password

Delete an user

The effect of the command

userdel fred

is given by the following code:

user='fred'
group='fred'
niutil -destroy . /users/$user
niutil -destroyval . /groups/$group users $user

Using dscl

Examine users and groups

The groups list can be examined with:

dscl . -list /Groups

The frontrow group's properties can be examined with:

dscl . -read /Groups/frontrow

The users list can be examined with:

dscl . -list /Users

The frontrow user's properties can be examined with:

dscl . -read /Users/frontrow

Modify users and groups

The following scripts

provide the functionality of the corresponding Linux commands based on dscl commands

Add a group

The effect of the command

groupadd -g 100 users

is given by the following code:

group='users'
group_id=100
dscl . -create /Groups/$group
dscl . -create /Groups/$group PrimaryGroupID $group_id
dscl . -create /Groups/$group Password '*'

Delete a group

The effect of the command

groupdel users

is given by the following code:

group='users'
dscl . -delete /Groups/$group

Add an user

The effect of the command

useradd -m fred

is given by the following code:

user='fred'
password='fred'
user_id=500
group_id=100
group_name="$user"
home_directory="/Users/$user"
real_name="$user"
login_shell=`which bash`
dscl . -create /Users/$user
dscl . -append /Groups/$group_name GroupMembership $user
mkdir -p $home_directory
chown $user:$group_name $home_directory
dscl . -create /Users/$user NFSHomeDirectory $home_directory
dscl . -create /Users/$user UserShell $login_shell
dscl . -create /Users/$user RealName  $real_name
dscl . -passwd /Users/$user $password

Delete an user

The effect of the command

userdel fred

is given by the following code:

user='fred'
group='fred'
dscl . -delete /Users/$user
dscl . -delete /Groups/$group GroupMembership $user