文件的权限管理

#1,创建g1组,要求创建一个属于redhat用户g1组的文件redhat.txt

[root@hahaha ~]#groupadd g1
[root@hahaha ~]# gpasswd  g1 -a talentman
Adding user talentman to group g1
[root@hahaha ~]# touch /redhat.txt
[root@hahaha ~]# chown :g1 /redhat.txt
[root@hahaha ~]# ll /redhat.txt
-rw-r--r--. 1 talentman g1 0 May  7 19:55 /redhat.txt

#2,新建/sc目录,所属组为group组,root用户和group用户可以在该目录下创建文件,其他人无任何权限

[root@hahaha ~]# mkdir /sc

[root@hahaha ~]# groupadd group

[root@hahaha ~]# chown :group /sc

[root@hahaha ~]# chmod g+w /sc

[root@hahaha ~]# ll -d /sc
drwxrwxr-x. 2 root group 6 Apr 25 19:32 /sc
[root@hahaha ~]# chmod 770 /sc
[root@hahaha ~]# ll -d /sc
drwxrwx---. 2 root group 6 Apr 25 19:32 /sc

#3,新建/cw目录视为财务部储存目录,只能对财务部人员可以写入,并且财务部人员所建立的文件都自动属于mygroup中

[root@hahaha ~]# mkdir /cw

[root@hahaha ~]# groupadd mygroup

[root@hahaha ~]# useradd zhangsan
[root@hahaha ~]# useradd lisi
[root@hahaha ~]# gpasswd -M zhangsan,lisi mygroup
[[roothahaha ~]# su - zhangsan

[zhangsan@hahaha ~]$ touch /cw/file1
touch: cannot touch '/cw/file1': Permission denied

[root@hahaha ~]# chmod 770 /cw
[root@hahaha ~]# ll -d /cw
drwxrwx---. 2 root mygroup 6 May  7 20:33 /cw

[root@hahaha ~]# su - zhangsan 
-bash: /etc/profile: line 82: syntax error: unexpected end of file
-bash: alias: hello: not found
-bash: alias: =/usr/bin/hello: not found
[zhangsan@hahaha ~]$ touch /cw/file4
[zhangsan@hahaha ~]$ 
[zhangsan@hahaha ~]$ ll /cw
total 0
-rw-r--r--. 1 lisi     lisi     0 May  7 20:48 file1
-rw-r--r--. 1 zhangsan zhangsan 0 May  7 20:51 file2
-rw-r--r--. 1 zhangsan zhangsan 0 May  7 21:30 file4


#4,设置helen用户对于/sc和/cw目录可读,可写,可执行

[root@hahaha ~]# useradd helen

[root@hahaha ~]# setfacl -m u:helen:rwx /sc 
[root@hahaha ~]# getfacl /sc
getfacl: Removing leading '/' from absolute path names
# file: sc
# owner: root
# group: group
user::rwx
user:helen:rwx
group::rwx
mask::rwx
other::---

[root@hahaha ~]# setfacl -m u:helen:rwx /cw 
[root@hahaha ~]# getfacl /cw
getfacl: Removing leading '/' from absolute path names
# file: cw
# owner: root
# group: mygroup
user::rwx
user:helen:rwx
group::rwx
mask::rwx
other::---


#5,设置/test目录为公共储存目录可读,对所有用户可以读,写,执行,但用户只能删除属于自己的文件。

[root@hahaha ~]# touch /test 
[root@hahaha ~]# chmod 777 /test

[root@hahaha ~]# ll -d /test
drwxrwxrwx. 3 root root 21 May  7 22:09 /test

[root@hahaha ~]# su - helen

[helen@hahaha ~]$ touch /test/file1

[helen@hahaha ~]$ su - talentman

[talentman@hahaha ~]$ touch /test/file2

[talentman@hahaha ~]$ ll /test
total 0
drwxr-xr-x. 2 root      root      45 Apr  9 19:12 class01
-rw-r--r--. 1 helen     helen      0 May  7 22:12 file1
-rw-r--r--. 1 talentman talentman  0 May  7 22:12 file2

[talentman@hahaha ~]$ rm -f /test/file1
rm: cannot remove '/test/file1': Operation not permitted

[talentman@hahaha ~]$ rm -f /test/file2
[talentman@hahaha ~]$ ll /test
total 0
drwxr-xr-x. 2 root  root  45 Apr  9 19:12 class01
-rw-r--r--. 1 helen helen  0 May  7 22:12 file1
 

#6,在/test/dir里创建的新文件自动属于与temp组

[talentman@hahaha ~]$ mkdir /test/dir

[talentman@hahaha ~]$ chmod g+s /test/di

[talentman@hahaha ~]$ ll -d /test/dir
drwxr-sr-x. 2 talentman talentman 6 May  7 22:26 /test/dir

talentman@hahaha ~]$ chmod o+w /test/dir
[talentman@hahaha ~]$ ll -d /test/dir
drwxr-srwx. 2 talentman talentman 6 May  7 22:26 /test/dir

[root@hahaha ~]# groupadd temp
[root@hahaha ~]# chown :temp /test/dir

[root@hahaha ~]# su - wukong
-bash: /etc/profile: line 82: syntax error: unexpected end of file
-bash: alias: hello: not found
-bash: alias: =/usr/bin/hello: not found
[wukong@hahaha ~]$ touch /test/dir/1
[root@hahaha ~]# su - helen
-bash: /etc/profile: line 82: syntax error: unexpected end of file
-bash: alias: hello: not found
-bash: alias: =/usr/bin/hello: not found
[helen@hahaha ~]$ touch /test/dir/2

[helen@hahaha ~]$ ll /test/dir
total 0
-rw-r--r--. 1 wukong temp 0 May  7 22:35 1
-rw-r--r--. 1 helen  temp 0 May  7 22:36 2








 


 

  • 17
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
头歌Linux是一种基于Linux内核的操作系统,它采用了类Unix的文件权限管理机制。文件权限管理是指对文件或目录进行访问控制和权限设置的过程。在头歌Linux中,每个文件或目录都有三种基本权限:读取权限、写入权限和执行权限。以下是头歌Linux文件权限管理的介绍: 1. 文件权限表示方式: - r(读取权限):表示可以读取文件内容或查看目录中的文件列表。 - w(写入权限):表示可以修改文件内容或在目录中创建、删除文件。 - x(执行权限):表示可以执行文件或进入目录。 2. 文件权限组合: - 文件拥有者权限:文件的所有者对文件具有特定的权限。 - 文件所属组权限:文件所属组的成员对文件具有特定的权限。 - 其他用户权限:除了文件拥有者和所属组成员外的其他用户对文件具有特定的权限。 3. 文件权限设置: - 使用chmod命令可以设置文件或目录的权限。例如,chmod 755 file.txt表示将file.txt文件的拥有者设置为可读、可写、可执行,所属组和其他用户设置为可读、可执行。 - 使用chown命令可以修改文件或目录的拥有者。例如,chown user file.txt将file.txt文件的拥有者修改为user。 - 使用chgrp命令可以修改文件或目录的所属组。例如,chgrp group file.txt将file.txt文件的所属组修改为group。 4. 文件权限查看: - 使用ls命令可以查看文件或目录的权限。例如,ls -l file.txt将以长格式显示file.txt文件的权限信息。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值