码迷,mamicode.com
首页 > 系统相关 > 详细

linux-用户及组管理

时间:2018-07-28 13:37:47      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:--help   登陆用户   进程   and   ESS   only   ubuntu   useradd   登陆   

用户及组管理

环境:ubuntu-16.04.4-server-amd64

/etc/passwd
root:x:0:0:root:/root:/bin/bash
用户名称 用户密码 用户ID 主组ID 注释 用户目录 shell
x表示加密(点位符)

/etc/group
root:x:0:
组名称 组密码 组ID 组内用户(多个以逗号分隔)
通常用户组不需要密码

/etc/shadow
root:!:17738:0:99999:7:::
用户名称 用户密码

useradd [option] newuser
-c, --comment COMMENT GECOS field of the new account
-g, --gid GROUP name or ID of the primary group of the new account
-G, --groups GROUPS list of supplementary groups of the new account
-h, --help display this help message and exit
-m, --create-home create the user‘s home directory 创建目录/home/new-user
-r, --system create a system account
-s, --shell SHELL login shell of the new account
-u, --uid UID user ID of the new account 否则系统默认分配

passwd newuser

usermod [option] newuser
-c, --comment COMMENT new value of the GECOS field
-d, --home HOME_DIR new home directory for the user account
-g, --gid GROUP force use GROUP as new primary group
-G, --groups GROUPS new list of supplementary GROUPS
-h, --help display this help message and exit
-l, --login NEW_LOGIN new value of the login name
-m, --move-home move contents of the home directory to the new location (use only with -d)
-s, --shell SHELL new login shell for the user account
-u, --uid UID new UID for the user account

userdel [option] newuser
-h, --help display this help message and exit
-r, --remove remove home directory and mail spool
对于已经登陆用户,需要取得其相关进程id,kill之,再删除
# ps -ef|grep newuser
root 2112 1128 0 11:06 ? 00:00:00 sshd: newuser [priv]
newuser 2114 1 0 11:06 ? 00:00:00 /lib/systemd/systemd --user
newuser 2115 2114 0 11:06 ? 00:00:00 (sd-pam)
newuser 2150 2112 0 11:06 ? 00:00:00 sshd: newuser@pts/1
newuser 2151 2150 0 11:06 pts/1 00:00:00 -sh
root 2157 1618 0 11:06 pts/0 00:00:00 grep --color=auto newuser
# kill 2112
# userdel -r newuser
# ll /home
#cat /etc/passwd

groupadd [option] newgroup
-g, --gid GID use GID for the new group 类似useradd -u即自定义id
-h, --help display this help message and exit
-r, --system create a system account

groupmod [option] newgroup
-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

groupdel newgroup
如果删除的组是某些用户的主组,需要解除关系才可删除,比如修改这些用户的-g
# usermod -g 0 newuser
# groupdel newgroup

 

linux-用户及组管理

标签:--help   登陆用户   进程   and   ESS   only   ubuntu   useradd   登陆   

原文地址:https://www.cnblogs.com/dailycode/p/9381349.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!