Linux运维系统工程师系列02

本文发布时间: 2019-Mar-22
用户管理:useraddusermoduserdelidpasswd组管理:groupadd ——添加组groupmod ——修改组groupdel——删除组gpasswd——设置密码添加组[[email protected] ~]# groupadd grp1[[email protected] ~]# tail -1 /etc/groupgrp1:x:2016:修改组:[[email protected] ~]# groupmod -g 2116 grp1[[email protected] ~]# tail -1 /etc/groupgrp1:x:2116:[[email protected] ~]# groupmod -n group1 grp1[[email protected] ~]# tail -1 /etc/groupgroup1:x:2116:删除组:[[email protected] ~]# groupdel group1[[email protected] ~]# tail -1 /etc/group看不到group1usr6:x:2015:注意:可以删除用户的附加组,不能删除用户的主组假设有we1和we2两个用户,分别属于we1组和we2组[[email protected] ~]# useradd we1[[email protected] ~]# useradd we2[[email protected] ~]# tail -2 /etc/passwdwe1:x:2021:2021::/home/we1:/bin/bashwe2:x:2022:2022::/home/we2:/bin/bash[[email protected] ~]# tail -2 /etc/groupwe1:x:2021:we2:x:2022:[[email protected] ~]# groupdel we2groupdel: cannot remove the primary group of user 'we2'[[email protected] ~]# usermod -g we1 we2[[email protected] ~]# groupdel we2[[email protected] ~]# groupadd we2[[email protected] ~]# usermod -G we2 we2[[email protected] ~]# id we2uid=2022(we2) gid=2021(we1) groups=2021(we1),2022(we2)[[email protected] ~]# groupdel we2gpasswd 给组设置密码[[email protected] ~]# gpasswd we1Changing the password for group we1New Password:Re-enter new password:newgrp 组名 用户输入密码后,可以获得相应组的资源,如:创建的文件属组为[[email protected] ~]# gpasswd u7Changing the password for group u7New Password:Re-enter new password:[[email protected] ~]# su - u8[[email protected] ~]$ touch u8[[email protected] ~]$ lltotal 0-rw-rw-r--. 1 u8 u8 0 Oct 14 14:10 u8[[email protected] ~]$ newgrp u7Password:[[email protected] ~]$ touch u8_7[[email protected] ~]$ lltotal 0-rw-rw-r--. 1 u8 u8 0 Oct 14 14:10 u8-rw-r--r--. 1 u8 u7 0 Oct 14 14:11 u8_7[[email protected] ~]$ iduid=2024(u8) gid=2024(u8) groups=2024(u8)[[email protected] ~]$ newgrp u7Password:[[email protected] ~]$ iduid=2024(u8) gid=2023(u7) groups=2024(u8),2023(u7) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023练习:1、添加组g20,指定gid为3000[[email protected] ~]# groupadd -g 3000 g20[[email protected] ~]# tail -1 /etc/groupg20:x:3000:2、修改g20组的gid为3002[[email protected] ~]# groupmod -g 3002 g20[[email protected] ~]# tail -1 /etc/groupg20:x:3002:3、修改g20组的名字为grp20[[email protected] ~]# groupmod -n grp20 g20[[email protected] ~]# tail -1 /etc/groupgrp20:x:3002:4、给grp20组设置密码为group20[[email protected] ~]# gpasswd grp20Changing the password for group grp20New Password:Re-enter new password:5、创建用户u20,使用id验证用户信息;切换u20的组为grp20,用id验证gid的变化[[email protected] ~]# useradd u20[[email protected] ~]# id u20uid=2025(u20) gid=2025(u20) groups=2025(u20)[[email protected] ~]# su - u20 #切换用户[[email protected] ~]$ whoamiu20[[email protected] ~]$ newgrp grp20#切换组Password:[[email protected] ~]$ iduid=2025(u20) gid=3002(grp20) groups=2025(u20),3002(grp20)


(以上内容不代表本站观点。)
---------------------------------
本网站以及域名有仲裁协议。
本網站以及域名有仲裁協議。

2019-May-25 12:57pm
栏目列表