您的位置:首页 > 运维架构 > Linux

Linux用户管理:addgroup、adduser、usermod

2016-04-16 12:02 666 查看

1 addgroup

和 groupadd是一个命令。

student@student16-x1:~$ 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
-R, --root CHROOT_DIR         directory to chroot into


示例:

#groupadd -g 344 cjh
此时在/etc/passwd文件中产生一个组ID(GID)是344的项目。


2 adduser

student@student16-x1:~$ adduser -h
adduser [--home DIR] [--shell SHELL] [--no-create-home] [--uid ID]
[--firstuid ID] [--lastuid ID] [--gecos GECOS] [--ingroup GROUP | --gid ID]
[--disabled-password] [--disabled-login] [--encrypt-home] USER
Add a normal user

adduser --system [--home DIR] [--shell SHELL] [--no-create-home] [--uid ID]
[--gecos GECOS] [--group | --ingroup GROUP | --gid ID] [--disabled-password]
[--disabled-login] USER
Add a system user

adduser --group [--gid ID] GROUP
addgroup [--gid ID] GROUP
Add a user group

addgroup --system [--gid ID] GROUP
Add a system group

adduser USER GROUP
Add an existing user to an existing group

general options:
--quiet | -q      don't give process information to stdout
--force-badname   allow usernames which do not match the
NAME_REGEX[_SYSTEM] configuration variable
--help | -h       usage message
--version | -v    version number and copyright
--conf | -c FILE  use FILE as configuration file


示例:

添加一个一般用户

# useradd kk //添加用户kk


为添加的用户指定相应的用户组

# useradd -g root kk //添加用户kk,并指定用户所在的组为root用户组


创建一个系统用户

# useradd -r kk //创建一个系统用户kk


为新添加的用户指定/home目录

# useradd -d /home/myf kk //新添加用户kk,其home目录为/home/myf
//当用户名kk登录主机时,系统进入的默认目录为/home/myf


3 usermod

usermod不允许你改变正在线上的使用者帐号名称。当usermod用来改变userID,必须确认这名user没在电脑上执行任何程序。

-a|--append         ##把用户追加到某些组中,仅与-G选项一起使用
-c|--comment        ##修改/etc/passwd文件第五段comment
-d|--home           ##修改用户的家目录通常和-m选项一起使用
-e|--expiredate     ##指定用户帐号禁用的日期,格式YY-MM-DD
-f|--inactive       ##用户密码过期多少天后采用就禁用该帐号,0表示密码已过期就禁用帐号,-1表示禁用此功能,默认值是-1
-g|--gid            ##修改用户的gid,改组一定存在
-G|--groups         ##把用户追加到某些组中,仅与-a选项一起使用
-l|--login          ##修改用户的登录名称
-L|--lock           ##锁定用户的密码
-m|--move-home      ##修改用户的家目录通常和-d选项一起使用
-s|--shell          ##修改用户的shell
-u|--uid            ##修改用户的uid,该uid必须唯一
-U|--unlock         ##解锁用户的密码


示例:

把test用户加入usertest组

#usermod -aG usertest test ##多个组之间用空格隔开
#id test
uid=5
ace0
00(test) gid=500(test) groups=500(test),501(usertest)


修改test用户的家目录

#usermod -md /home/usertest
#ls /home
usertest


修改用户名

#usermod -l urchin(新用户名称)  test(原来用户名称)
#id urchin
uid=500(urchin) gid=500(test) groups=500(test),501(usertest)


修改用户的UID

#usermod -u 578 urchin (UID必须唯一)
#id urchin
uid=578(urchin) gid=500(test) groups=500(test),501(usertest)


修改用户的GID

#groupadd -g 578 test1
#usermod -g 578 urchin (578组一定要存在)
#id urchin
uid=578(urchin) gid=578(test1) groups=578(test1),501(usertest)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息