centos系统添加/删除用户和用户组

建用户

# 新建phpq用户
adduser phpq
# 给phpq用户设置密码
passwd phpq   

建工作组

# 新建test工作组
groupadd test   

新建用户同时增加工作组

# 新建phpq用户并增加到test工作组
useradd -g test phpq 

给已有的用户增加工作组


usermod -G groupname username
# or
gpasswd -a username groupname 

临时关闭

在/etc/shadow文件中属于该用户的行的第二个字段(密码)前面加上就可以了。想恢复该用户,去掉即可。

或者使用如下命令关闭用户账号:

passwd peter –l
# 重新释放:
passwd peter –u

永久性删除用户账号

userdel peter
groupdel peter
usermod –G peter peter   (强制删除该用户的主目录和主目录下的所有文件和子目录)

从组中删除用户

编辑/etc/group 找到GROUP1那一行,删除 A 或者用命令 gpasswd -d A GROUP

显示用户信息

id user

cat /etc/passwd

查看用户和用户组

用户列表文件:/etc/passwd

用户组列表文件:/etc/group

查看系统中有哪些用户:cut -d : -f 1 /etc/passwd

查看可以登录系统的用户:cat /etc/passwd | grep -v /sbin/nologin | cut -d : -f 1

查看某一用户:w 用户名

查看登录用户:who

查看用户登录历史记录:last

Subscribe to ionantha

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe