linux如何创建权限文件,Linux如何使用setfacl命令创建权限文件

setfacl是Linux下设置文件访问控制列表的命令,可用来创建文件,能够继承目录的权限,有些功能类似于chmod命令,下面小编就给大家介绍下Linux使用setfacl命令创建权限文件的方法,一起来学习下吧。

下面以 root 用普通用户 user1 。在目录/mnt下

[root@RedHat-7 mnt]# setfacl -m u:user1:rwx share //为目录添加ower = user1 ,并赋予rwx 的权根。

[root@redhat-7 mnt]# setfacl -d -m u:user1:rwx share //为目录添加默认的acl权限,此目录下创建目录和文件都会继承此权限信息

[root@redhat-7 mnt]#

[root@redhat-7 mnt]#

[root@redhat-7 mnt]# getfacl share //查看share的facl信息

# file: share

# owner: root

# group: root

user::rwx

user:user1:rwx // 此时user1才能对share有写权限

group::r-x

mask::rwx

other::r-x

default:user::rwx //默认子目录或文件的权限信息

default:user:user1:rwx

default:group::r-x

default:mask::rwx

default:other::r-x

[root@redhat-7 mnt]# cd share/

[root@redhat-7 share]# ls

[root@redhat-7 share]# touch roota

[root@redhat-7 share]# touch rootb

[root@redhat-7 share]# mkdir rootdir1

[root@redhat-7 share]# mkdir rootdir2

[root@redhat-7 share]# ls

roota rootb rootdir1 rootdir2

[root@redhat-7 share]# getfacl roota

# file: roota

# owner: root

# group: root

user::rw-

user:user1:rwx #effective:rw-

group::r-x #effective:r--

mask::rw-

other::r--

[root@redhat-7 share]# getfacl rootdira

getfacl: rootdira: No such file or directory

[root@redhat-7 share]# getfacl rootdir

rootdir1/ rootdir2/

[root@redhat-7 share]# getfacl rootdir1

# file: rootdir1

# owner: root

# group: root

user::rwx

user:user1:rwx

group::r-x

mask::rwx

other::r-x

default:user::rwx

default:user:user1:rwx

default:group::r-x

default:mask::rwx

default:other::r-x

[root@redhat-7 share]#

现在用user1 进入此目录来检测权限:

[user1@redhat-7 share]$

[user1@redhat-7 share]$

[user1@redhat-7 share]$

[user1@redhat-7 share]$ ll

total 8

-rw-rw-r--+ 1 root root 0 Nov 19 22:52 roota

-rw-rw-r--+ 1 root root 0 Nov 19 22:52 rootb

drwxrwxr-x+ 2 root root 6 Nov 19 22:52 rootdir1

drwxrwxr-x+ 2 root root 6 Nov 19 22:52 rootdir2

[user1@redhat-7 share]$ touch user1a

[user1@redhat-7 share]$ touch user1dir1

[user1@redhat-7 share]$ getfacl user1a //查看新文件的权限

# file: user1a

# owner: user1

# group: user1

user::rw-

user:user1:rwx #effective:rw-

group::r-x #effective:r--

mask::rw-

other::r--

[user1@redhat-7 share]$ rm roota //尝试删除root创建的文件,成功

[user1@redhat-7 share]$ rm rootdir1 //尝试删除root创建的目录,成功

rm: cannot remove arootdir1a: Is a directory

[user1@redhat-7 share]$ rm rootdir1 -r

[user1@redhat-7 share]$ ll

total 4

-rw-rw-r--+ 1 root root 0 Nov 19 22:52 rootb

drwxrwxr-x+ 2 root root 6 Nov 19 22:52 rootdir2

-rw-rw-r--+ 1 user1 user1 0 Nov 19 22:57 user1a

-rw-rw-r--+ 1 user1 user1 0 Nov 19 22:57 user1dir1

[user1@redhat-7 share]$

所以,当有需求要做权根的继承操作时,可以使用这个方来实现。

在新的rhel7 中, 会有新的工具chacl 类似于 setfacl 。

上面就是Linux使用setfacl命令创建权限文件的方法介绍了,因为创建的文件继承了父目录的权限,所以在某些时候使用比较方便,当然setfacl命令还有其他的用法。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值