groupadd grouptest1添加一个叫grouptest1的用户组。
useradd gooduser -g grouptest1添加一个叫gooduser 的用户,并把它添加到grouptest1用户组里边,id gooduser看一下用户的信息。
接下来进行测试用户和用户组权限。
普通文件
在root账户下,mkdir /test新建一个目录,然后在使用touch /test/filetest在/test目录下新建一个filetest空文件。

使用chown gooduser:grouptest1 /test/filetest把filetest的属主更换成gooduser,把属组更换成grouptest1。

chmod 000 /test/filetest把所属用户、所属用户组和其他用户都设置成没有任何权限。

su - gooduser把用户切换成gooduser,发现cat /test/filetest读文件没有权限,echo "123" > /test/filetest写文件没有权限。

su - root切换成root用户,然后使用chmod u+w /test/filetest给属主加上写的权限。

su - gooduser切换成gooduser用户,echo "123" > /test/filetest发现已经有写的权限了,cat /test/filetest发现还是没有读的权限。

chmod u+r /test/filetest给文件添加上读的权限。cat /test/filetest发现还是已经有读的权限。

至于普通文件执行的权限,还需要shell脚本测试。
目录文件
su - root切换成root用户,然后chown gooduser:grouptest1 /test把目录的属主改成gooduser,把目录的属组改成grouptest1。

chmod 000 /test把目录/test的所有权限去掉。

su - gooduser切换成gooduser用户,对于目录文件,若是没有“x”权限,那么就无法进入。

chmod u+x /test把执行权限加给/test,发现可以进入了,但是无法读取目录里边的内容。

chmod u+r /test把读权限加给/test,可以读取目录里边的内容,无法在目录中新建文件。

chmod u+w /test把写权限加给/test,可以在目录中新建文件。

此文章为6月Day 16学习笔记,内容来源于极客时间《Linux 实战技能 100 讲》。



















