Linux file permissions and access control

Source: Internet
Author: User

Linux file permissions and access control

Access file User 3 class:

    文件所有者    同组成员    其他人

Permissions
---------(rwx) corresponds to 3 categories of users in turn

file:6rw 4r 0 x1dir: 7rwx 5r-x 0

Default Permissions

umask内部命令 用来生成数字 umask+default =file666/dir777umask +数字 修改umask值umask 本质含义取消对应权限    原理计算:            666                 666            125                 125            110110110           541            001010101           542     对于文件偶数不动奇数全加一                                        对于目录不必要这么做,目录            110100010                   执行权限没有担心            642 配置文件        个人用户配置  .bashrc 在文件末尾追加 umask 251   source .bashrc          /etc/bashrc 下配置了root和普通用户的umask默认值            root 022  普通 002umask     -p >> .bashrc 追加umask值到个人配置文件中    

Command:

chmod     法一:        chmod who opt per file            who:u g o(a可以代表ugo)            opt:+ - =            per: r w x (X s .特殊权限)    ps: chmod u+x,g-w,o= file     参考一个文件权限修改另一个文件    chmod --reference=filename1 filename2 filename3    法二:数字法        r:4        w:2        x:1        chmod 764 filename    chmod -R a+x dirname 递归加执行权限    chmod -R +X dirname X仅仅对目录加执行,文件不加执行                        当文件原有执行权限则会加执行权限chown    -c或——changes:效果类似“-v”参数,但仅回报更改的部分;    -f或--quite或——silent:不显示错误信息;    -h或--no-dereference:只对符号连接的文件作修改,而不更改其他任何相关文件;    -R或——recursive:递归处理,将指定目录下的所有文件及子目录一并处理;    -v或——version:显示指令执行过程;    --dereference:效果和“-h”参数相同;    --help:在线帮助;    --reference=<参考文件或目录>:把指定文件或目录的拥有者与所属群组全部设成和参考文件或目录的拥有者与所属群组相同;    --version:显示版本信息。    chown root:root         chown .root file    只改属组    chown root. file 属主属组全改chgrp

Special permissions:

SUID:作用在继承二进制程序所有者的x位上,当一个用户运行该程序,由于存在s权限      则它会继承该程序的属主的权限。只适合在二进制可执行程序上。    chmod u+s(-s)          4---      都表示加s权限。SGID: 作用在所有者的x位上,当一个用户运行该程序,由于存在s权限      则它会继承该程序的属组的权限    chmod g+s           4---sticky1:粘滞位。无法删除别人的文件,即使2人都拥有其目录的w权限,作用                在文件夹上。    chmod o+t           1---SUID: user,占据属主的执行权限位          s: 属主拥有x权限          S:属主没有x权限 ?SGID: group,占据属组的执行权限位          s: group拥有x权限          S:group没有x权限 Sticky: other,占据other的执行权限位          t: other拥有x权限          T:other没有x权限

############################################
Chattr
Chattr +i (-i) cannot be deleted, renamed, changed
Chattr +a (-a) can only append content
Chattr +a (-a) lock Atime time VI modify file after lock invalidation
Lsattr Display Specific Properties
############################################

Access Control List ACL:

ACL:Access Control List,实现灵活的权限管理     除了文件的所有者,所属组和其它人,可以对更多的用户设置权限      CentOS7 默认创建的xfs和ext4文件系统具有ACL功能 后续添加的分区也支持    CentOS7 之前版本,默认手工创建的ext4文件系统无ACL功能,需手动增加         tune2fs –o acl /dev/sdb1         mount –o acl /dev/sdb1  /mnt/test     ACL生效顺序:所有者,自定义用户,自定义组,其他人        若属于多个组的话,若没有用户权限匹配则多个组权限可以累积

#############################################
Group permissions have been changed to mask permission after ACL is enabled
#############################################

Grant access to files and directories for multiple users or groups rwx mount-o acl/directory getfacl file |directory view ACL permissions for files or directories setfacl-m u:wang:rwx File|dir Ectory setfacl-rm g:sales:rwx directory recursive setfacl-m file.acl file|directory Bulk Add setfacl-m g:salesgrou via file invocation P:RW file|  Directory setfacl-m d:u:wang:rx directory permissions settings for new files in directory setfacl-x U:wang file |directory setfacl-x file.acl Directory file Bulk Delete permissions The group permission on the ACL file is the mask value (custom user, custom group, with maximum permissions for the group), rather than the traditional group permissions setfacl-m mask::r file sets the Mask permission Tfacl can see special permissions: Flags give directory default X permissions through ACLs, directory files will not inherit the X permission base ACL cannot remove setfacl-k dir remove default ACL permissions setfacl–b file1 Clear all ACL permissions get Facl File1 | Setfacl--set-file=-file2 copy file1 ACL permissions to File2 mask requires logical AND operation with the user's permissions before it becomes a limited permission (effective Permission) The settings of the user or group must exist in mask Within the scope of the permission is not effective setfacl-m Mask::rx file--set option will remove the original ACL entries, with a new alternative, it is important to note that it is necessary to include the Ugo settings, not as-m just add ACLs can be shown Example: Setfacl--set u::rw,u:wang:rw,g::r,o::-file1 backup and restore ACL primary file Operations Command CP and MV both support ACLs, but the CP command needs to be prefixed with the-p parameter. However, common backup tools such as tar do not preserve directories andACL information for files Getfacl-r/tmp/dir1 > Acl.txt setfacl-r-b/tmp/dir1 setfacl-r--set-file=acl.txt/tmp/dir1 (No Be sure to fully recover you can choose one of the files or directory recovery) recursively restore ACL permissions according to the Acl.txt file, or you can implement a single file or directory recovery setfacl--restore acl.txt restore ACL permissions getfacl-r/tmp/di     R1

Linux file permissions and access control

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.