一.创建用户
1.创建新用户: useradd 用户名
id 用户名 (查看用户信息)
[root@VM_0_5_centos ~]# useradd redwine
[root@VM_0_5_centos ~]# id redwine
uid=1003(redwine) gid=1004(redwine) groups=1004(redwine)
2.创建用户的同时加入组 useradd -g 组名 用户名
[root@VM_0_5_centos home]# useradd -g root redwine
[root@VM_0_5_centos home]# id redwine
uid=1003(redwine) gid=0(root) groups=0(root)
3.修改用户密码: passwd 用户名
[root@VM_0_5_centos home]# passwd redwine
Changing password for user redwine.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
切换用户:
[wenhongjun@VM_0_5_centos home]$ su redwine
Password:
[redwine@VM_0_5_centos home]$
4.删除用户: userdel 用户名
[root@VM_0_5_centos ~]# userdel -r redwine
[root@VM_0_5_centos ~]# id redwine
id: redwine: no such user
5.查看系统中的所有用户或者用户组
cat /etc/passwd
cat /etc/group
二.创建用户组
1.新建组: groupadd 组名 删除组: groupdel 组名
[root@VM_0_5_centos home]# groupadd group1
[root@VM_0_5_centos home]# groupdel group1
2.给已有的用户增加工作组
usermod -g 组名(A) 用户名(B)//将A加入组B(该命令用于修改用户的基本信息)
或者
gpasswd -a 用户名 组名
[root@VM_0_5_centos home]# usermod -g group1 redwine
[root@VM_0_5_centos home]# id redwine
uid=1003(redwine) gid=1004(group1) groups=1004(group1)
3.将用户从组中移除
gpasswd -d 用户名 组名
[root@VM_0_5_centos home]# gpasswd -a redwine root
Adding user redwine to group root
[root@VM_0_5_centos home]# gpasswd -d redwine root
Removing user redwine from group root