1 作业一:
2 1) 新建用户natasha,uid为1000,gid为555,备注信息为“master”
3 groupadd -g 555 natasha
4 useradd -u 1000 -g 555 -c master natasha
5 id natasha
6
7 2) 修改natasha用户的家目录为/Natasha
8 cd /home
9 usermod -md /Natasha natasha
10
11 3) 查看用户信息配置文件的最后一行
12 tail -1 /etc/passwdtai
13
14 4) 为natasha用户设置密码“123”
15 echo '123' | passwd --stdin natasha
16
17 5) 查看用户密码配置文件的最后一行
18 tail -1 /etc/shadow
19
20 6) 将natasha用户账户锁定
21 usermod -L natasha
22
23 7) 将natasha用户账户解锁
24 usermod -U natasha
25
26 8) 新建组police,gid为1999
27 groupadd -g 1999 police
28
29 9) 查看组配置文件的最后一行
30 tail -1 /etc/group
31
32 10) 将natasha用户加入police组
33 usermod natasha -a -G police
34
35 11) 修改police组的组名为jingcha
36 groupmod -n jingcha police
37
38 12) 删除natasha用户,连家目录和邮箱一起删除
39 userdel -r natasha
40
41 13) 删除jingcha组
42 groudel jingcha
43
44 作业二:
45 1) 在用户的主目录下创建目录test,进入test创建空文件file1
46 mkdir /test/
47 cd /test
48 touch file1
49
50 2) 以长格式形式显示文件信息,注意文件的权限和所属用户和组
51 ls -l file1
52
53 3) 为文件file1设置权限,使其他用户可以对此文件进行写操作。
54 chmod o=r file1
55
56 4) 查看设置结果
57 ls -l file1
58
59 5) 取消同组用户对文件file1的读取权限,并查看设置结果。
60 chmod g-r file1
61 ls -l file1
62
63 6) 用数字表示法为文件file设置权限,所有者可读、可写、可执行,所属组用户和其他用户只具有读和执行的权限。设置完成后查看设置结果。
64 chmod 755 file1
65 ls -l filel
66
67 7) 用数字形式更改文件file1的权限,使所有者只能读取此文件。其他任何用户都没有权限。查看设置结果。
68 chmod 400 file1
69 ls -l filel
70
71 8) 回到上层目录,查看test的权限
72 cd ..
73 ll -d /test
74
75 9) 为其他用户添加对此目录的写权限
76 chmod -R 0+w /test
77
78
79
80 作业三:
81 以操作文件的方式,新建一个用户alex
82 [root@localhost /]# vim /etc/passwd 添加内容:#alex:x:2001:1001:alex:/home/alex:/bin/bash
83 [root@localhost /]# vim /etc/shadow 添加内容:#alex:$6$5p8WDDqDOhrEhzbSNe.enZJpJZR387pc0::0:99999:7:::
84 [root@localhost /]# vim /etc/group 添加内容:#alex:x:1001:alex
85 [root@localhost /]# vim /etc/gshadow 添加内容:#alex:!!::alex
86 [root@localhost /]# mkdir /home/alex
87 [root@localhost /]# cp -r /etc/skel/.[!.]* /home/alex
88 [root@localhost /]# chown -R alex:alex /home/alex/
89 [root@localhost /]# touch /var/spool/mail/alex
90 [root@localhost /]# chown alex:mail /var/spool/mail/alex
91 [root@localhost /]# id alex
92 uid=2001(alex) gid=1001(alex) 组=1001(alex)
93 [root@localhost /]#
94
95 作业四:
96 1) 新建目录/test/dir,属主为tom,数组为group1,/test目录的权限为777
97 useradd tom
98 echo '123' | passwd --stdin tom
99 groupadd group1
100 mkdir -p /test/dir
101 chown tom:group1 /test/dir
102 chmod 777 /test/
103
104 2) 新建用户jack,切换到jack用户下,验证jack用户对dir目录的rwx权限(开启另外一个终端,依次修改dir目录的others权限)
105 useradd jack
106 echo '123' | passwd --stdin jack
107 su - jack
108 ll -d /test/dir
109 验证: 修改权限:
110 ll -d /test/dir chmod 0=- /test/dir
111 touch /test/dir/yanzheng.txt
112 cd /test/dir
113
114 3)将jack加入group1组,验证jack用户对dir目录的rwx权限(开启另外一个终端,依次修改dir目录的group权限)
115 usermod jack -a -G group1
116 验证: 修改权限:
117 ll -d /test/dir chmod g+w /test/dir
118 rm /test/dir/yanzheng.txt
119 cd /test/dir
120
121 4)切换到tom用户,验证tom用户对dir目录的rwx权限(开启另外一个终端,依次修改dir目录的user权限)
122 su - tom
123 验证:
124 ls /test/dir
125 touch /test/dir/yanzheng.txt
126 cd /test/dir
127
128 5)在dir目录内新建文件tom.txt,属主为tom,属组为group1,/test目录的权限为777
129 touch /test/dir/tom.txt
130 chown tom:group1 /test/dir/tom.txt
131 chmod 777 /test
132
133 6)新建用户rose,切换到rose用户下,验证rose用户对tom.txt的rwx权限(开启另外一个终端,依次修改tom.txt的others权限来配合验证过程)
134 useradd rose
135 echo '123' | passwd --stdin rose
136 su - rose
137 验证:
138 cat /test/dir/tom.txt
139 echo '11111111'>> /test/dir/tom.txt
140 ./test/dir/tom.txt
141 7)将rose加入group1组,在rose用户下,验证rose用户对tom.txt的rwx权限(开启另外一个终端,依次修改tom.txt的group1权限来配合验证过程)
142 usermod rose -a -G group1
143 su - rose
144 验证:
145 cat /test/dir/tom.txt
146 echo '2222222'>> /test/dir/tom.txt
147 ./test/dir/tom.txt
148
149 8)切换到tom用户,验证tom用户对tom.txt的rwx权限(开启另外一个终端,依次修改tom.txt的user权限来配合验证过程)
150 su - tom
151 验证:
152 cat /test/dir/tom.txt
153 echo '3333333'>> /test/dir/tom.txt
154 ./test/dir/tom.txt