Chapter04

 1、创建/guanli 目录,在/guanli下创建zonghe 和 jishu 两个目录(一条命令)
[root@localhost ~]#
[root@localhost ~]# mkdir -pv /guanli/zonghe | mkdir -pv /guanli/jishu
mkdir: 已创建目录 "/guanli"
mkdir: 已创建目录 "/guanli/jishu"
[root@localhost ~]# cd /guanli/
[root@localhost guanli]# ls
jishu  zonghe
[root@localhost guanli]#
2、添加组帐号zonghe、caiwu、jishu,GID号分别设置为2001、2002、2003
[root@localhost ~]# groupadd -g 2001 zonghe | groupadd -g 2002 caiwu | groupadd -g 2003 jishu
[root@localhost ~]# tail -8 /etc/group
jiaoxue:x:1002:
ss:x:1003:
test1:x:1004:
test2:x:1005:
test3:x:1006:
jishu:x:2003:
caiwu:x:2002:
zonghe:x:2001:
3、创建jerry、kylin、tsengia、obama用户,其中的kylin用户帐号在2020年12月30日后失效
[root@localhost ~]# useradd jerry | useradd kylin | useradd tsengia | useradd obama
[root@localhost ~]# usermod -e 2020-12-30 kylin
[root@localhost ~]# tail -3 /etc/shadow
kylin:!!:18107:0:99999:7::18626:
4、将jerry、kylin、tsengia、obama等用户添加到zonghe组内
[root@localhost ~]# gpasswd -M jerry,kylin,tsengia,obama zonghe
[root@localhost ~]# tail -4 /etc/group
tsegia:x:1004:
zonghe:x:2001:jerry,kylin,tsengia,obama
caiwu:x:2002:
jishu:x:2003:
[root@localhost ~]#
5、创建handy、cucci用户,其中cucci帐号的登录Shell设置为“/sbin/nologin”
[root@localhost ~]# useradd handy
[root@localhost ~]# useradd -s /sbin/nologin cucci
[root@localhost ~]# tail -2 /etc/passwd
handy:x:1005:1005::/home/handy:/bin/bash
cucci:x:1006:1006::/home/cucci:/sbin/nologin
6、将handy、cucci等用户添加到jishu组内
[root@localhost ~]#
[root@localhost ~]# gpasswd -M handy,cucci jishu
[root@localhost ~]# tail -8 /etc/group
kylin:x:1002:
jerry:x:1003:
tsegia:x:1004:
zonghe:x:2001:jerry,kylin,tsegia,obama
caiwu:x:2002:
jishu:x:2003:handy,cucci
handy:x:1005:
cucci:x:1006:
7、将上述的所有用户均要求加入到guanli组内
[root@localhost ~]# gpasswd -M handy,cucci,jerry,kylin,tsengia,obama guanli
[root@localhost ~]# tail /etc/group
guanli:x:2004:handy,cucci,jerry,kylin,tsengia,obama
8、将zonghe组内的obama用户删除
[root@localhost ~]# vi /etc/group
zonghe:x:2001:jerry,kylin,tsegia
9、为jerry用户设置密码为“123456”(使用普通方法)
   为cucci用户设置密码为“redhat”(使用--stdin方法) 
[root@localhost ~]# passwd jerry
更改用户 jerry 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@localhost ~]# echo "redhat" | passwd --stdin cucci
更改用户 cucci 的密码 。
passwd:所有的身份验证令牌已经成功更新。
10、将jerry用户锁定,并查看锁定状态
[root@localhost ~]# passwd -l jerry
锁定用户 jerry 的密码 。
passwd: 操作成功
[root@localhost ~]# passwd -S jerry
jerry LK 2019-07-30 0 99999 7 -1 (密码已被锁定。)
11、打开两个xshell窗口,通过(who 或者 w)命令查看连接状态,并通过fuser杀掉其中一个
[root@localhost ~]# who
root     :0           2019-07-30 15:39 (:0)
root     pts/0        2019-07-30 15:39 (:0)
root     pts/1        2019-07-30 15:41 (192.168.100.126)
root     pts/2        2019-07-30 16:06 (192.168.100.126)
[root@localhost ~]# fuser -k /dev/pts/2
/dev/pts/2:           9780
[root@localhost ~]#
12、查看cucci用户,属于那些组,并查看其详细信息
[root@localhost ~]# groups cucci
cucci : cucci jishu guanli
[root@localhost ~]# finger cucci
Login: cucci             Name:
Directory: /home/cucci               Shell: /sbin/nologin
Never logged in.
No mail.
No Plan.
[root@localhost ~]# finger
Login     Name       Tty      Idle  Login Time   Office     Office Phone   Host
root      root      *:0             Jul 30 15:39                           (:0)
root      root       pts/0      33  Jul 30 15:39                           (:0)
root      root       pts/1          Jul 30 15:41                           (192.168.100.126)
13、手工创建账号student
 [root@localhost ~]# vi /etc/group
最后一行加入student:x:2000:保存并退出
[root@localhost ~]# vi /etc/passwd
最后一行加入student:x:2001:2000::/home/student:/bin/bash保存并退出
[root@localhost ~]# vi /etc/shadow
进入后使用yyp这一行复制到最后并进行改编cucci:!!$6$Jo7ZqnHk$rVpYu8/3xvNIkqDpEViNEnir4hki2vVVS/gotNPEGvr2PbafNX65N7anoXnslTzvyaBmmWdIPmEHov2JWS7Sn/:18107:0:99999:7:::
student:$6$Jo7ZqnHk$rVpYu8/3xvNIkqDpEViNEnir4hki2vVVS/gotNPEGvr2PbafNX65N7anoXnslTzvyaBmmWdIPmEHov2JWS7Sn/:18107:0:99999:7:::
[root@localhost ~]# mkdir -pv /home/student
mkdir: 已创建目录 "/home/student"
[root@localhost ~]# cp -R /etc/skel/ /home/student/
[root@localhost ~]# chown -R student:student /home/student
[root@localhost ~]# chmod -R go= /home/student、
[root@localhost ~]# su student
bash-4.2$ exit
[root@localhost ~]# cp /etc/skel/.bashrc /home/student/
[root@localhost ~]# cp /etc/skel/.bash_logout /home/student/
[root@localhost ~]# cp /etc/skel/.bash_profile /home/student/
[root@localhost ~]# su student
[student@localhost root]$ su
14、设置权限及归属:
   /guanli目录属组设为guanli
   /guanli/zonghe目录的属组设为zonghe
   /guanli/jishu目录的属组设为jishu
   设置3个目录都是禁止其他用户访问的权限
[root@localhost ~]# chown :guanli /guanli/
[root@localhost ~]# chown :zonghe /guanli/zonghe
[root@localhost ~]# chown :jishu /guanli/jishu
[root@localhost ~]# chmod -R o=--- /guanli
[root@localhost ~]# ll /guanli/
总用量 0
drwxr-x---. 2 root jishu  6 7月  30 16:46 jishu
drwxr-x---. 2 root zonghe 6 7月  30 16:46 zonghe
15、建立公共目录/ceshi
   允许技术组内的所有用户读取、写入、执行文件
   禁止其他用户读、写、执行
[root@localhost ~]# mkdir /ceshi
[root@localhost ~]# chown :jishu /ceshi
[root@localhost ~]# chmod g=xwr /ceshi
[root@localhost ~]# chmod o=--- /ceshi
[root@localhost ~]# ls -l /
总用量 28
lrwxrwxrwx.   1 root root     7 7月  29 09:24 bin -> usr/bin
dr-xr-xr-x.   5 root root  4096 7月  29 09:34 boot
drwxrwx---.   2 root jishu    6 7月  30 17:34 ceshi  
16、清除jerry用户密码
[root@localhost ~]# passwd -S jerry
jerry LK 2019-07-30 0 99999 7 -1 (密码已被锁定。)
[root@localhost ~]# passwd -u jerry
解锁用户 jerry 的密码。
17、锁定cucci用户密码并查看状态
[root@localhost ~]# passwd -l cucci
锁定用户 cucci 的密码 。
passwd: 操作成功
[root@localhost ~]# passwd -S cucci
cucci LK 2019-07-30 0 99999 7 -1 (密码已被锁定。)
18、修改obama用户的UID为8888
[root@localhost ~]# groupadd -g 8888 obama
[root@localhost ~]# tail -9 /etc/group
kylin:x:1002:
jerry:x:1003:
tsegia:x:1004:
zonghe:x:2001:jerry,kylin,tsegia
caiwu:x:2002:
jishu:x:2003:handy,cucci
handy:x:1005:
cucci:x:1006:
obama:x:8888:
19、通过passwd命令修改kylin用户的最长密码使用期限为60天
[root@localhost ~]# passwd -x 60 kylin
调整用户密码老化数据kylin。
passwd: 操作成功
[root@localhost ~]# tail /etc/shadow
kylin:!!:18107:0:60:7::18626:
20、通过id groups finger等命令查看用户handy信息
[root@localhost ~]# id handy
uid=1005(handy) gid=1005(handy) 组=1005(handy),2003(jishu)
[root@localhost ~]# groups handy
handy : handy jishu
[root@localhost ~]# finger handy
Login: handy             Name:
Directory: /home/handy               Shell: /bin/bash
Never logged in.
No mail.
No Plan.
[root@localhost ~]#
posted @ 2019-07-31 10:25  啥子无聊  阅读(116)  评论(0编辑  收藏  举报