用户与组账号创建与删除

用户账号操作

[root@FQDN ~]# useradd he     //创建用户:useradd+用户名
[root@FQDN ~]# passwd -S he   //显示口令状态:passwd –S+用户名
he LK 2018-01-04 0 99999 7 -1 (Password locked.)
[root@FQDN ~]# passwd he     //设置口令:passwd+用户名
Changing password for user he.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@FQDN ~]# su – he       //切换账号:su – +用户名
[he@FQDN ~]$ su - root
Password: 
Last login: Thu Jan  4 20:08:05 CST 2018 on :0
[root@FQDN ~]# su - he
Last login: Thu Jan  4 20:14:45 CST 2018 on pts/0
[he@FQDN ~]$ passwd       //修改口令:passwd  
Changing password for user he.
Changing password for he.
(current) UNIX password: 
New password: 
BAD PASSWORD: The password fails the dictionary check - it is too simplistic/systematic
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.
[he@FQDN ~]$ exit          //退回root账号
logout
[root@FQDN ~]# passwd -S he   
he PS 2018-01-04 0 99999 7 -1 (Password set, SHA512 crypt.)
[root@FQDN ~]# passwd -l he   //锁定用户:passwd –l +用户名
Locking password for user he.
passwd: Success
[root@FQDN ~]# passwd -S he
he LK 2018-01-04 0 99999 7 -1 (Password locked.)
[root@FQDN ~]# passwd -u he  //解除锁定:passwd –u +用户名
Unlocking password for user he.
passwd: Success
[root@FQDN ~]# passwd -S he
he PS 2018-01-04 0 99999 7 -1 (Password set, SHA512 crypt.)
[root@FQDN home]# chage -d 0 he  //口令时效:chage -d +天数+用户名
[root@FQDN home]# chage -l he    //显示时效:chage -l +用户名
Last password change					: password must be changed
Password expires					: password must be changed
Password inactive					: password must be changed
Account expires						: never
Minimum number of days between password change		: 0
Maximum number of days between password change		: 99999
Number of days of warning before password expires	: 7
[root@FQDN ~]# userdel he       // 删除用户: userdel +用户名

组操作

[root@FQDN ~]#groupadd long   // 创建组:groupadd + 组名
[root@FQDN ~]# usermod -G long new  //添加用户到组:usermod –G +组名+用户名
[root@FQDN ~]# whoami       //显示当前用户名称:whoami
root
[root@FQDN ~]# groups        //显示当前组名称:groups   
root
[root@FQDN ~]# groups new    //显示指定用户所属的组:# groups + 组名
new : new long
[root@FQDN ~]# id            //显示用户当前uid、gid和用户所属的组:id
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[root@FQDN ~]# su - new
[new@FQDN ~]$ id
uid=1002(new) gid=1003(new) groups=1003(new),1001(long) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[new@FQDN ~]$ touch abc
[new@FQDN ~]$ ll abc          //查看文件所属的用户和组:ll+文件名
-rw-rw-r--. 1 new new 0 Jan  5 09:51 abc
[new@FQDN ~]$ newgrp long
[new@FQDN ~]$ id
uid=1002(new) gid=1001(long) groups=1001(long),1003(new) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[new@FQDN ~]$ touch xyz
[new@FQDN ~]$ ll
total 0
-rw-rw-r--. 1 new new  0 Jan  5 09:51 abc
-rw-r--r--. 1 new long 0 Jan  5 09:52 xyz
[new@FQDN ~]$ exit            //退回上一次的登录:exit  
exit
[new@FQDN ~]$ exit
logout
[root@FQDN ~]# userdel -r new
[root@FQDN ~]# userdel -r he
[root@FQDN ~]# groupdel long   //删除组:groupdel+组名


你可能感兴趣的:(Linux学习)