飞翔

I can believe fly.

Wednesday, July 3, 2019

mac下用户用户组命令行操作

使用mac的时候需要像linux一样对用户和群组进行操作,但是linux使用的gpasswd和usermod在mac上都不可以使用,mac使用dscl来对group和user操作。
查看用户组:
1
dscl . list /groups
 查看用户:
1
dscl . list /users
 添加用户组:
1
sudo dscl . -create /Groups/test
 删除用户组:
1
sudo dscl . -delete /Groups/test
 添加用户:
1
sudo dscl .  -create /Users/redis
 删除用户:
1
sudo dscl . -delete /Users/redis
 显示所有users对应的group:
1
sudo dscl . -list /groups GroupMembership
 添加user到group:
1
sudo dscl . -append /Groups/groupname GroupMembership username
从group中删除user:
1
sudo dscl . -delete /Groups/groupname GroupMembership username
 other:
1
2
3
dscl . -create /Groups/GROUP
dscl . -create /Groups/GROUP PrimaryGroupID GID
dscl . -create /Groups/GROUP Password \*

1
2
3
4
5
6
7
dscl . -create /Users/USER
dscl . -create /Users/USER UniqueID UID
dscl . -create /Users/USER UserShell /usr/bin/false
dscl . -create /Users/USER RealName 'DESCRIPTION'
dscl . -create /Users/USER NFSHomeDirectory DIRECTORY
dscl . -create /Users/USER PrimaryGroupID GID
dscl . -create /Users/USER Password \*
 显示所有用户组的ID
1
dscl . -list /Groups PrimaryGroupID
 读取用户组的信息:
1
2
3
4
5
6
7
8
9
10
11
12
13
dscl . read /groups/wheel
结果:
AppleMetaNodeLocation: /Local/Default
GeneratedUID: ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000000
GroupMembers: FFFFEEEE-DDDD-CCCC-BBBB-AAAA00000000
GroupMembership: root
Password: *
PrimaryGroupID: 0
RealName:
 System Group
RecordName: wheel
RecordType: dsRecTypeStandard:Groups
 读取用户组下的成员:
1
2
3
4
dscl . read /groups/wheel GroupMembership
结果:
GroupMembership: root