Linux - 用户管理 - 用户组

【基本介绍】
Linux系统的一大块就是用户管理,管理用户的信息,这里介绍用户组。
常用的命令有groupadd , groupdel , gpasswd , groups , finger

用户组分为两类:
私有组->在创建一个新用户时,若没有指定所属于的组,linux将建立一个和用户同名的私有组
标准组->可以容纳多个用户,若使用标准组创建一个新用户是应该指定该用户的所在组

【基本操作】
添加用户组:可以用groupadd,也可以useradd
[code="linux"]
# groupadd --help
Usage: groupadd [options] GROUP

Options:
-f, --force exit successfully if the group already exists,
and cancel -g if the GID is already used
-g, --gid GID use GID for the new group
-h, --help display this help message and exit
-K, --key KEY=VALUE override /etc/login.defs defaults
-o, --non-unique allow to create groups with duplicate
(non-unique) GID
-p, --password PASSWORD use this encrypted password for the new group
-r, --system create a system account

[/code]

[code="linux"]
# grep test /etc/group
# groupadd test
# grep test /etc/group
test:x:508:
[/code]
useradd -g 组名 用户名 ----创建用户并将该用户加入到组中

修改用户组
[code="linux"]
# groupmod --help
Usage: groupmod [options] GROUP
Options:
-g, --gid GID change the group ID to GID
-h, --help display this help message and exit
-n, --new-name NEW_GROUP change the name to NEW_GROUP
-o, --non-unique allow to use a duplicate (non-unique) GID
-p, --password PASSWORD change the password to this (encrypted)
PASSWORD
[/code]

[code="linux"]
# groupmod -n ttest test
# grep test /etc/group
ttest:x:508:
[/code]

添加删除用户组:
[code="linux"]
# gpasswd --help
gpasswd: unrecognized option '--help'
Usage: gpasswd [option] GROUP
Options:
-a, --add USER add USER to GROUP
-d, --delete USER remove USER from GROUP
-r, --remove-password remove the GROUP's password
-R, --restrict restrict access to GROUP to its members
-M, --members USER,... set the list of members of GROUP
-A, --administrators ADMIN,...
set the list of administrators for GROUP
Except for the -A and -M options, the options cannot be combined.
[/code]

[code="linux"]
# gpasswd -a spark ttest
Adding user spark to group ttest
# grep ttest /etc/group
ttest:x:508:spark
[/code]

[code="linux"]
# grep ttest /etc/group
ttest:x:508:spark
# gpasswd -d spark ttest
Removing user spark from group ttest
# grep ttest /etc/group
ttest:x:508:
[/code]

groupdel 用户组名 ----删除用户组,该帐号必须存在且不能作为某个用户的私有组引用(不能删除私有组和不存在的组),如果该组中还有其他用户在使用,必须先删除组中的用户才能删除该组

查看用户组
[code="linux"]
# man groups
GROUPS(1) User Commands GROUPS(1)
NAME
groups - print the groups a user is in
SYNOPSIS
groups [OPTION]... [USERNAME]...

DESCRIPTION
Print group memberships for each USERNAME or, if no USERNAME is specified, for the current process (which may differ if the groups
database has changed).
[/code]
groups 用户名 ----查看用户属于哪个组
[code="linux"]
# groups spark
spark : spark
# gpasswd -a spark ttest
Adding user spark to group ttest
# groups spark
spark : spark ttest
[/code]

【参考】
[url]http://bbs.chinaunix.net/thread-3751354-1-1.html[/url]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值