linux同组用户与其它用户对文件夹权限的测试/(包含用户添加、目录创建、组的添加修改、目录的权限更改等命令)

1、先以管理员身份创建两个测试用户:test001,test002。 

      [root@cent home]# useradd test001
      [root@cent home]# useradd test002

移动到/home文件夹下用# ll 命令查看,是否有与新建用户对应的同名文件夹

      [root@cent home]# ll

       drwx------.  3 test001 test001   78 Apr  5 21:23 test001
       drwx------.  3 test002 test002   78 Apr  5 21:24 test002

注:用户创建成功后,系统默认会在/home目录创建与新建用户名相同的目录,且同时创建与新建用户同名的组。

 

2、设置新建test001,test002用户的密码。

注:只有root用户才能设置新用户密码。

[root@cent cent]# passwd test001

Changing password for user test001
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.

 

3、创建一个名为testgroup的组,并将test001、test002用户添加至该组。

注:此步骤没有提示信息,需要在cat /etc/group目录下查看是否创建成功。(该目录是系统用来存放组信息文件的)

[root@cent cent]# groupadd testgroup

查看用户组信息

[root@cent cent]# cat /etc/group

可以看到在文件的最后面生成了刚才我们创建的testgroup组

test001:x:1003:
test002:x:1004:
testgroup:x:1008:

将test001与test002用户添加至testgroup组。

[root@cent cent]# usermod -G testgroup test001
[root@cent cent]# usermod -G testgroup test002

查看组文件信息,可以看到test001,test002被添加到了testgroup组里。

[root@cent cent]# cat /etc/group

testgroup:x:1008:test001,test002

 

4、在/home目录下创建testing目录用作测试权限。

[root@cent home]# mkdir testing

查看testing目录可以看到此时的testing目录的所有者与所属组为root。

[root@cent home]#ll

drwxr-xr-x.  2 root    root       6 Apr  5 21:36 testing

 

5、修改testing目录所属组为testgroup

下面语法修改的组名为附加组方式

[root@cent home]# chgrp  testgroup testing/
drwxr-xr-x.  2 root    testgroup    6 Apr  5 21:36 testing

 

修改目录的所有者为test001。

[root@cent home]# chown test001 testing/
drwxr-xr-x.  2 test001 testgroup    6 Apr  5 21:36 testing

 

到此目录的修改与用户组的调整已经完成。

通过下列信息,我们可以看到testing目录的所有者test001、testgroup组、其他人对testing目录的操作权限分别是rwx、r-x、r-x。

drwxr-xr-x.  2 test001 testgroup    6 Apr  5 21:36 testing

 

6、修改testing目录的权限为rwx、r-x、---。

[root@cent home]#chmod 750 testing/

查看文件夹信息
drwxr-x---.  2 test001 testgroup    6 Apr  5 21:36 testing

此时可以看到testing的权限由drwxr-xr-x变为了drwxr-x---

 

7、创建新用户test003作为其他用户,给它设置一个密码。

[root@cent home]# useradd test003

[root@cent home]# passwd test003
Changing password for user test003.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.

 

查看用户组信息文件,多了一个test003的组,我们刚才创建的test003用户默认属于test003组

[root@cent home]# cat /etc/group
est003:x:1009:

 

 

8、测试其他用户对testing目录的操作权限

切换其它用户test003登录系统

注:su - 表示连同当前工作的环境一同切换。- 后面别忘了加空格。

[root@cent home]# su - test003

 

移动到testing目录下,提示权限不足。这是因为我们设置了其他人对testing目录无操作权限。

[test003@cent ~]$ cd /home/testing/
-bash: cd: /home/testing/: Permission denied

 

9、切换test001同组用户登录测试testing目录权限

我们切换与testing目录所有者test001为同一组的test002用户再次操作。

重复操作发现,同组用户test002用户可以移动到testing目录下,可以读。

[test003@cent ~]$ su - test002
[test002@cent ~]$ cd /home/testing/

 

test002用户在testing目录下无法创建文件。提示权限不足

这是因为同组用户对testing目录的操作权限为r-x,也就是没有写权限,

[test002@cent testing]$ touch test.txt
touch: cannot touch ‘test.txt’: Permission denied

 

 

 

 

 

 

 

思路:

 

新建三个用户:test001、test002、test003。(语法:useradd 用户名)

           

新建用户组:testgroup。(语法:groupadd 组名)

           

将test001与test002移动至testgroup组中,test003为单独的一组。(语法:usermod -G 组名 用户名      注:-G为附加组,-g为主组)

         

 创建testing目录,且将testing目录权限更改为:drwxr-x---。(语法:mkdir 目录名,语法:chmod 750 目录名)

  最前面的d代表目录,最前面-开头为文档。r:4,w:2,x:1.

 

更改testing目录所有者所属组(语法:chown 所有者 目录,chgrp 所属组 目录。)

 

测试同组用户test002对testing目录的权限,测试其他用户test003对testing目录的操作权限。

 

至此,结束。

  • 3
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值