Linux ACL权限与chmod -R 777 /类型恢复

本文详细介绍了ACL(Access Control List)在Linux系统中的应用,包括如何使用setfacl和getfacl命令进行权限的设置与获取。通过实例解析,读者可以了解到如何针对单一用户、文件或目录进行更精细的权限控制。

ACL即Access Control List 主要的目的是提供传统的owner,group,others的read,write,execute权限之外的具体权限设置,ACL可以针对单一用户、单一文件或目录来进行r、w、x的权限控制,对于需要特殊权限的使用状况有一定帮助。如,某一个文件,不让单一的某个用户访问。

如果一个文件后面有+标记,我们都需要用getfacl来确认它的permission,以免发生混淆;

如果你的文件系统不支持ACL的话,你也许需要重新mount你的file system:mount -o remount,acl [mount point],查看是否支持ACL:tune2fs -l /dev/sda1

一、setfacl——设定文件访问控制列表
语法: setfacl [-bkndRLP] { -m|-M|-x|-X … } file …
-m, --modify=acl 更改文件的访问控制列表
-M, --modify-file=file 从文件读取访问控制列表条目更改
-x, --remove=acl 根据文件中访问控制列表移除条目
-X, --remove-file=file 从文件读取访问控制列表条目并删除
-b, --remove-all 删除所有扩展访问控制列表条目
-k, --remove-default 移除默认访问控制列表
–set=acl 设定替换当前的文件访问控制列表
–set-file=file 从文件中读取访问控制列表条目设定
–mask 重新计算有效权限掩码
-n, --no-mask 不重新计算有效权限掩码
-d, --default 应用到默认访问控制列表的操作
-R, --recursive 递归操作子目录
-L, --logical 依照系统逻辑,跟随符号链接
-P, --physical 依照自然逻辑,不跟随符号链接
–restore=file 恢复访问控制列表,和“getfacl -R”作用相反;通过这种机制可以恢复整个目录树的acl规则还有特殊权限。此参数不能和除–test以外的任何参数一同执行。
–test 测试模式,并不真正修改访问控制列表属性
-v, --version 显示版本并退出
-h, --help 显示本帮助信息

二、getfacl ——获取文件访问控制列表
使用方法: getfacl [-aceEsRLPtpndvh] 文件 …
-a, --access 仅显示文件访问控制列表
-d, --default 仅显示默认的访问控制列表,仅能用于目录文件
-c, --omit-header 不显示注释表头
-e, --all-effective 显示所有的有效权限
-E, --no-effective 显示无效权限
-s, --skip-base 跳过只有基条目(base entries)的文件
-R, --recursive 递归显示子目录
-L, --logical 逻辑遍历(跟随符号链接)
-P, --physical 物理遍历(不跟随符号链接)
-t, --tabular 使用制表符分隔的输出格式
-n, --numeric 显示数字的用户/组标识
-p, --absolute-names 不去除路径前的 ‘/’ 符号
-v, --version 显示版本并退出
-h, --help 显示本帮助信息

setfacl命令可以识别以下的规则格式:

  • [d[efault]:] [u[ser]:]uid [:perms] 指定用户的权限,文件所有者的权限(如果uid没有指定)。
  • [d[efault]:] g[roup]:gid [:perms] 指定群组的权限,文件所有群组的权限(如果gid未指定)
  • [d[efault]:] m[ask][:] [:perms] 有效权限掩码
  • [d[efault]:] o[ther] [:perms] 其他的权限

类型 说明
user::rw- 定义了ACL_USER_OBJ, 说明file owner拥有read and write permission
user:john:rw- 定义了ACL_USER,这样用户john就拥有了对文件的读写权限,实现了我们一开始要达到的目的
group::rw- 定义了ACL_GROUP_OBJ,说明文件的group拥有read and write permission
group:dev:r-- 定义了ACL_GROUP,使得dev组拥有了对文件的read permission
mask::rw- 定义了ACL_MASK的权限为read and write
other::r-- 定义了ACL_OTHER的权限为read
注:ACL_MASK它规定了ACL_USER,ACL_GROUP_OBJ和ACL_GROUP的最大权限。那么在我们这个例子中他们的最大权限也就是read only。虽然我们这里给ACL_USER和ACL_GROUP_OBJ设置了其他权限,但是他们真正有效果的只有read权限;
ACL_MASK是掌握ACL的另一个关键,在Linux file permission里面大家都知道比如对于rw-rw-r–来说, 当中的那个rw-是指文件组的permission. 但是在ACL里面这种情况只是在ACL_MASK不存在的情况下成立。如果文件有ACL_MASK值,那么当中那个rw-代表的就是mask值而不再是group permission了;
Mask只对其他用户和组的权限有影响,对owner和other的权限是没有任何影响的。

每一个Access Entry都是由两个被‘:’号分隔开的字段所组成,
第一个就是Entry tag type。

  • user 对应了ACL_USER_OBJ和ACL_USER
  • group 对应了ACL_GROUP_OBJ和ACL_GROUP
  • mask 对应了ACL_MASK
  • other 对应了ACL_OTHER
    第二个字段称之为qualifier,也就是上面例子中的john和dev组,它定义了特定用户和拥护组对于文件的权限。这里我们也可以发现只有user和group才有qualifier,其他的都为空。
    第三个字段就是我们熟悉的permission了

实际例子:
在10.27.65.16 root用户下执行:
导出权限表:
getfacl -pR /usr > /home/root/acl.bak

在10.27.65.17 root用户下执行:
导入权限表(同时恢复特殊权限):
setfacl --restore /home/root/acl.bak

查看已有权限:getfacl /usr/bin/ssh
设置用户权限:setfacl -m user:weblogic:rwx ./test/
setfacl -m u:testu1:rwx,g:testg1:r file1
设置有效权限掩码:setfacl -m m::w test.txt1

设置默认权限(在此目录下建立的文件都可以被weblogic用户所访问):setfacl -d -m user:weblogic:rwx /tmp/test1/
删除ACL权限:setfacl -x g:testg1 file1

这个是什么问题 我现在是包下载好了 但是编译不成功 make[3]: Entering directory '/data/red-round3/red-round3/Iplatform/packages/opensource/samba' mkdir -p /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25 cp -fpR ./src/* /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25 touch /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/.prepared_c2d0a16b7871c64b29f76be535b29d9d (cd /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/source3/; if [ -x ./configure ]; then /usr/bin/find /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/ -name config.guess | xargs -r chmod u+w; /usr/bin/find /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/ -name config.guess | xargs -r -n1 cp /data/red-round3/red-round3/Iplatform/openwrt/scripts/config.guess; /usr/bin/find /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/ -name config.sub | xargs -r chmod u+w; /usr/bin/find /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/ -name config.sub | xargs -r -n1 cp /data/red-round3/red-round3/Iplatform/openwrt/scripts/config.sub; AR=arm-buildroot-linux-gnueabi-ar AS="arm-buildroot-linux-gnueabi-gcc -c -DMAX_DEBUG_LEVEL=-1 -D__location__=\\\"\\\" -ffunction-sections -fdata-sections" LD=arm-buildroot-linux-gnueabi-ld NM=arm-buildroot-linux-gnueabi-nm CC="arm-buildroot-linux-gnueabi-gcc" GCC="arm-buildroot-linux-gnueabi-gcc" CXX="arm-buildroot-linux-gnueabi-g++" RANLIB=arm-buildroot-linux-gnueabi-ranlib STRIP=arm-buildroot-linux-gnueabi-strip OBJCOPY=arm-buildroot-linux-gnueabi-objcopy OBJDUMP=arm-buildroot-linux-gnueabi-objdump SIZE=arm-buildroot-linux-gnueabi-size CFLAGS=" -DMAX_DEBUG_LEVEL=-1 -D__location__=\\\"\\\" -ffunction-sections -fdata-sections " CXXFLAGS=" -DMAX_DEBUG_LEVEL=-1 -D__location__=\\\"\\\" -ffunction-sections -fdata-sections " CPPFLAGS="-I/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/usr/include -I/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/include -I/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/usr-be220v1/include -I/data/red-round3/red-round3/Iplatform/openwrt/../../bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/usr/include " LDFLAGS="-L/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/usr/lib -L/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/lib -Wl,-rpath-link,/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/usr/lib -L/data/red-round3/red-round3/Iplatform/openwrt/../../bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/usr/lib -L/data/red-round3/red-round3/Iplatform/openwrt/../../bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/lib -Wl,--gc-sections -lubox -lubus -lifaddrs " ac_cv_lib_attr_getxattr=no ac_cv_search_getxattr=no ac_cv_file__proc_sys_kernel_core_pattern=yes libreplace_cv_HAVE_C99_VSNPRINTF=yes libreplace_cv_HAVE_IFACE_IFCONF=yes libreplace_cv_HAVE_GETADDRINFO=yes LINUX_LFS_SUPPORT=yes samba_cv_CC_NEGATIVE_ENUM_VALUES=yes samba_cv_HAVE_GETTIMEOFDAY_TZ=yes samba_cv_HAVE_IFACE_IFCONF=yes samba_cv_HAVE_KERNEL_OPLOCKS_LINUX=yes samba_cv_HAVE_SECURE_MKSTEMP=yes samba_cv_HAVE_WRFILE_KEYTAB=no samba_cv_USE_SETREUID=yes samba_cv_USE_SETRESUID=yes samba_cv_have_setreuid=yes samba_cv_have_setresuid=yes ac_cv_header_zlib_h=no samba_cv_zlib_1_2_3=no ./configure --target=arm-openwrt-linux-uclibc --host=arm-openwrt-linux-uclibc --build=x86_64-linux-gnu --program-prefix="" --program-suffix="" --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib --sysconfdir=/etc --datadir=/usr/share --localstatedir=/var --mandir=/usr/man --infodir=/usr/info --disable-nls --exec-prefix=/usr --prefix=/ --disable-avahi --disable-cups --disable-pie --disable-relro --disable-static --disable-swat --enable-shared-libs --with-codepagedir=/etc/samba --with-configdir=/etc/samba --with-included-iniparser --with-included-popt --with-lockdir=/var/lock --with-logfilebase=/var/log --with-nmbdsocketdir=/var/nmbd --with-piddir=/var/run --with-privatedir=/etc/samba --with-sendfile-support --without-acl-support --without-cluster-support --without-ads --without-krb5 --without-ldap --without-pam --without-winbind --without-libtdb --without-libtalloc --without-libnetapi --without-libsmbsharemodes --without-libtevent --without-libaddns --with-shared-modules=pdb_tdbsam,pdb_wbc_sam,idmap_nss,nss_info_template,auth_winbind,auth_wbc,auth_domain ; fi; ) rm -f /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/.configured_* touch /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/.configured_ CFLAGS=" -DMAX_DEBUG_LEVEL=-1 -D__location__=\\\"\\\" -ffunction-sections -fdata-sections -I/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/usr/include -I/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/include -I/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/usr-be220v1/include -I/data/red-round3/red-round3/Iplatform/openwrt/../../bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/usr/include " CXXFLAGS=" -DMAX_DEBUG_LEVEL=-1 -D__location__=\\\"\\\" -ffunction-sections -fdata-sections -I/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/usr/include -I/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/include -I/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/usr-be220v1/include -I/data/red-round3/red-round3/Iplatform/openwrt/../../bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/usr/include " LDFLAGS="-L/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/usr/lib -L/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/lib -Wl,-rpath-link,/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/usr/lib -L/data/red-round3/red-round3/Iplatform/openwrt/../../bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/usr/lib -L/data/red-round3/red-round3/Iplatform/openwrt/../../bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/lib -Wl,--gc-sections -lubox -lubus -lifaddrs " make -j1 -C /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/source3 AR=arm-buildroot-linux-gnueabi-ar AS="arm-buildroot-linux-gnueabi-gcc -c -DMAX_DEBUG_LEVEL=-1 -D__location__=\\\"\\\" -ffunction-sections -fdata-sections" LD=arm-buildroot-linux-gnueabi-ld NM=arm-buildroot-linux-gnueabi-nm CC="arm-buildroot-linux-gnueabi-gcc" GCC="arm-buildroot-linux-gnueabi-gcc" CXX="arm-buildroot-linux-gnueabi-g++" RANLIB=arm-buildroot-linux-gnueabi-ranlib STRIP=arm-buildroot-linux-gnueabi-strip OBJCOPY=arm-buildroot-linux-gnueabi-objcopy OBJDUMP=arm-buildroot-linux-gnueabi-objdump SIZE=arm-buildroot-linux-gnueabi-size CROSS="arm-buildroot-linux-gnueabi-" ARCH="arm" DYNEXP= PICFLAG= MODULES= ; make[4]: Entering directory '/data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/source3' make[4]: *** No targets specified and no makefile found. Stop. make[4]: Leaving directory '/data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/source3' Makefile:221: recipe for target '/data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/.built' failed make[3]: *** [/data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/.built] Error 2 make[3]: Leaving directory '/data/red-round3/red-round3/Iplatform/packages/opensource/samba' package/Makefile:133: recipe for target 'package/feeds/iplatform/samba/compile' failed make[2]: *** [package/feeds/iplatform/samba/compile] Error 2 make[2]: Leaving directory '/data/red-round3/red-round3/Iplatform/openwrt' /data/red-round3/red-round3/Iplatform/openwrt/include/toplevel.mk:184: recipe for target 'package/samba/compile' failed make[1]: *** [package/samba/compile] Error 2 make[1]: Leaving directory '/data/red-round3/red-round3/Iplatform/openwrt' Makefile:234: recipe for target 'iplatform_package/samba/compile' failed make: *** [iplatform_package/samba/compile] Error 2
最新发布
11-02
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值