Linux下使用简单的一条命令实现控制用户的目录访问权限

181 阅读1分钟

项目背景 在做Linux服务器管理时候由于有些生产环境上的信息,或者一些其他敏感的配置信息不让ftp或者普通用户访问,以达到信息安全和隐秘的要求

项目环境 操作系统 :centos7.2

涉及的命令:yum 、setfacl(访问控制权限)

安装ACL yum -y install acl

查看ACL是否安装成功

rpm -qa | grep acl

setfacl命令的用法

setfacl 2.2.51 – set file access control lists

Usage: setfacl [-bkndRLP] { -m|-M|-x|-X … } file …

-m, --modify=acl modify the current ACL(s) of file(s)

-M, --modify-file=file read ACL entries to modify from file

-x, --remove=acl remove entries from the ACL(s) of file(s)

-X, --remove-file=file read ACL entries to remove from file

-b, --remove-all remove all extended ACL entries

-k, --remove-default remove the default ACL

–set=acl set the ACL of file(s), replacing the current ACL

–set-file=file read ACL entries to set from file

–mask do recalculate the effective rights mask

-n, --no-mask don’t recalculate the effective rights mask

-d, --default operations apply to the default ACL

-R, --recursive recurse into

-L, --logical logical walk, follow symbolic links

-P, --physical physical walk, do not follow symbolic links

–restore=file restore ACLs (inverse of `getfacl -R’)

–test test mode (ACLs are not modified)

-v, --version print version and exit

-h, --help this help text

设置用户的访问权限 比如在服务器上希望普通用户ubuntu不能访问 /etc 、/usr等系统配置目录 , 则配置如下

setfacl -R -m u:ubuntu:- /etc /usr

-R表示递归,-m表示修改,u:ubuntu:-表示用户(user)ubuntu对/etc 和 /usr 没有任何权限。可以根据需要添加r、w、x及其组合。

取消用户的访问限制 setfacl -R -x u:ubuntu /etc /usr