chapter04作业

1、创建/guanli 目录,在/guanli下创建zonghe jishu 两个目录(一条命令)

[root@localhost ~]# mkdir -p /guanli/zonghe && mkdir /guanli/jishu

[root@localhost ~]# ls -R /guanli/

/guanli/:

jishu  zonghe

 

/guanli/jishu:

 

/guanli/zonghe:

2、添加组帐号zonghecaiwujishuGID号分别设置为200120022003

[root@localhost ~]# groupadd -g 2001 zonghe && groupadd -g 2002 caiwu && groupadd -g  2003 jishu

[root@localhost ~]# tail -3 /etc/group

zonghe:x:2001:

caiwu:x:2002:

jishu:x:2003:

3、创建jerrykylintsengiaobama用户,其中的kylin用户帐号在20201230日后失效

[root@localhost ~]# useradd jerry && useradd -e 2020-12-30 kylin && useradd tsengia && useradd obama

[root@localhost ~]# tail -4 /etc/shadow

jerry:!!:18107:0:99999:7:::

kylin:!!:18107:0:99999:7::18626:

tsengia:!!:18107:0:99999:7:::

obama:!!:18107:0:99999:7:::

4、将jerrykylintsengiaobama等用户添加到zonghe组内

[root@localhost ~]# gpasswd -M jerry,kylin,tsengia,obama zonghe

[root@localhost ~]# grep "^zonghe" /etc/group

zonghe:x:2001:jerry,kylin,tsengia,obama

5、创建handycucci用户,其中cucci帐号的登录Shell设置为“/sbin/nologin

[root@localhost ~]# useradd handy && useradd -s /sbin/nologin cucci &&tail -2 /etc/passwd

handy:x:1005:1005::/home/handy:/bin/bash

cucci:x:1006:1006::/home/cucci:/sbin/nologin

6、将handycucci等用户添加到jishu组内

[root@localhost ~]# gpasswd -M handy,cucci jishu && grep "^jishu" /etc/group

jishu:x:2003:handy,cucci

7、将上述的所有用户均要求加入到guanli组内

[root@localhost ~]# groupadd guanli && gpasswd -M  jerry,kylin,tsengia,obama,handy,cucci guanli && grep "^guanli" /etc/group

guanli:x:2004:jerry,kylin,tsengia,obama,handy,cucci

8、将zonghe组内的obama用户删除

[root@localhost ~]# gpasswd -d obama zonghe && grep "^zonghe" /etc/group

正在将用户obama”从“zonghe”组中删除

zonghe:x:2001:jerry,kylin,tsengia

9、jerry用户设置密码为“123456”(使用普通方法)

[root@localhost ~]# passwd jerry

更改用户 jerry 的密码 。

新的 密码:

无效的密码: 密码少于 8 个字符

重新输入新的 密码:

passwd:所有的身份验证令牌已经成功更新。

   cucci用户设置密码为“redhat”(使用--stdin方法)  

[root@localhost ~]# echo "redhat" | passwd --stdin cucci

更改用户 cucci 的密码 。

passwd:所有的身份验证令牌已经成功更新

10、将jerry用户锁定,并查看锁定状态

[root@localhost ~]# usermod -L jerry && passwd -S jerry

jerry LK 2019-07-30 0 99999 7 -1 (密码已被锁定。)

10、打开两个xshell窗口,通过(who 或者 w)命令查看连接状态,并通过fuser杀掉其中一个

[root@localhost ~]# who

(unknown) :0           2019-07-30 16:06 (:0)

root     pts/0        2019-07-30 16:08 (192.168.10.1)

root     pts/1        2019-07-30 17:06 (192.168.10.1)

[root@localhost ~]# w

 17:06:44 up  1:00,  3 users,  load average: 0.01, 0.02, 0.05

USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT

root     pts/0    192.168.10.1     16:08   44.00s  0.36s  0.36s -bash

root     pts/1    192.168.10.1     17:06    4.00s  0.36s  0.00s w

[root@localhost ~]# fuser -k /dev/pts/1

[root@localhost ~]# w

 17:07:43 up  1:01,  2 users,  load average: 0.00, 0.01, 0.05

USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT

root     pts/0    192.168.10.1     16:08    7.00s  0.36s  0.00s w

12、查看cucci用户,属于那些组,并查看其详细信息

[root@localhost ~]# groups cucci && finger cucci

cucci : cucci jishu guanli

Login: cucci           Name:

Directory: /home/cucci               Shell: /sbin/nologin

Never logged in.

No mail.

No Plan.

13、手工创建账号student

[root@localhost ~]# echo "student:x:1007:1007::/home/student:/bin/bnsh">> /etc/passwd && echo "student::18107:0:99999:7:::" >> /etc/shadow echo "student:x:1007:student" >> /etc/group && cp /etc/skel/.bash* /home/student

[root@localhost ~]# tail -1 /etc/passwd && tail -1 /etc/shadow && tail -1 /etc/group

student:x:1007:1007::/home/student:/bin/bnsh

cucci:$6$QrHcO4kz$0q2SeJ7MnH/XHRj1yJz3I5gDYs9LzvOFA2/P.S3iTaQDG.naAa7C/2BddDJ0e.O.fkU9jfvNbwsRglOLUeFuY/:18107:0:99999:7:::

student::18107:0:99999:7::: echo student:x:1007:student

14、设置权限及归属:

   /guanli目录属组设为guanli

[root@localhost ~]# chown :guanli /guanli/

[root@localhost ~]# ll -d /guanli/

drwxr-xr-x 4 root guanli 31 7月  30 16:46 /guanli/

   /guanli/zonghe目录的属组设为zonghe

[root@localhost ~]# chown :zonghe /guanli/zonghe/

[root@localhost ~]# ll -d /guanli/zonghe/

drwxr-xr-x 2 root zonghe 6 7月  30 16:46 /guanli/zonghe/

   /guanli/jishu目录的属组设为jishu

[root@localhost ~]# chown :jishu /guanli/jishu/ && ll -d /guanli/jishu/

drwxr-xr-x 2 root jishu 6 7月  30 16:46 /guanli/jishu/

   设置3个目录都是禁止其他用户访问的权限

[root@localhost ~]# chmod -R o=--- /guanli/ && ll R /guanli/ 

ls: 无法访问R: 没有那个文件或目录

/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 && setfacl -m g:jishu:rwx /ceshi && chmod o=--- /ceshi && getfacl /ceshi

getfacl: Removing leading '/' from absolute path names

# file: ceshi

# owner: root

# group: root

user::rwx

group::r-x

group:jishu:rwx

mask::rwx

other::---

16、清除jerry用户密码

[root@localhost ~]# passwd -d jerry && grep "^jerry" /etc/shadow

清除用户的密码 jerry

passwd: 操作成功

jerry::18107:0:99999:7:::

17、锁定cucci用户密码并查看状态

[root@localhost ~]# passwd -l cucci && passwd -S cucci

锁定用户 cucci 的密码 。

passwd: 操作成功

cucci LK 2019-07-30 0 99999 7 -1 (密码已被锁定。)

18、修改obama用户的UID8888

[root@localhost ~]# usermod -u 8888 obama && grep "^obama" /etc/passwd

obama:x:8888:1004::/home/obama:/bin/bash

19、通过passwd命令修改kylin用户的最长密码使用期限为60

[root@localhost ~]# passwd -x 60 kylin && grep "^kylin" /etc/shadow

调整用户密码老化数据kylin

passwd: 操作成功

kylin:!!:18107:0:60:7::18626:

20、通过id groups finger等命令查看用户handy信息

[root@localhost ~]# id handy && groups handy && finger handy

uid=1005(handy) gid=1005(handy) =1005(handy),2003(jishu),2004(guanli)

handy : handy jishu guanli

Login: handy           Name:

Directory: /home/handy               Shell: /bin/bash

Never logged in.

No mail.

No Plan.

原文地址:https://www.cnblogs.com/fengling1998/p/11276302.html