运维大法之Linux系统中的管理权限(二)设定普通权限的方法和系统默认权限设定以及文件用户用户组管理

1.设定普通权限的方法

chmod 设定文件权限

  • chmod 复制权限

chmod --reference=/tmp /mnt/westosdir
复制/tmp目录的权限到/mnt/westosdir上
运维大法之Linux系统中的管理权限(二)设定普通权限的方法和系统默认权限设定以及文件用户用户组管理
chmod -R --reference=/tmp /mnt/westosdir
复制/tmp目录的权限到/mnt/westosdir及 目录中的子文件上( -R 代表递归操作)
运维大法之Linux系统中的管理权限(二)设定普通权限的方法和系统默认权限设定以及文件用户用户组管理

  • chmod 字符方式设定权限

chmod <a|u|g|o><+|-|=><r|w|x> file
用字符方式设定文件权限

示例:
chmod u-rw /mnt/westosfile1
运维大法之Linux系统中的管理权限(二)设定普通权限的方法和系统默认权限设定以及文件用户用户组管理
chmod u-rw,g+x,o+wx /mnt/westosfile2
运维大法之Linux系统中的管理权限(二)设定普通权限的方法和系统默认权限设定以及文件用户用户组管理
chmod a-rwx /mnt/westosfile3
运维大法之Linux系统中的管理权限(二)设定普通权限的方法和系统默认权限设定以及文件用户用户组管理
chmod u=rwx,g=rx,o=— /mnt/westosfile4
运维大法之Linux系统中的管理权限(二)设定普通权限的方法和系统默认权限设定以及文件用户用户组管理
chmod -R u=rwx,g=rx,o=— /mnt/westosdir/
运维大法之Linux系统中的管理权限(二)设定普通权限的方法和系统默认权限设定以及文件用户用户组管理

  • chmod 数字方式设定权限

权限波尔指表示方式
rwx = 111
— = 000

三位二进制可以表示的最大范围为8进至数
rwx=111=7
rw-=110=6 r-x=101=5 r–=100=4=r -wx=011=3 -w-=010=2=w
–x=001=1=x
—=000=0

2系统默认权限设定

umask表示系统保留权力

umask 查看保留权力

umask 权限值
运维大法之Linux系统中的管理权限(二)设定普通权限的方法和系统默认权限设定以及文件用户用户组管理
临时设定系统预留权力
文件默认权限 = 777-umask-111
目录默认权限 = 777-umask
umask值越大系统安全性越高

  • umask临时更改
    umask 077
    -永久更改

3.文件用户用户组管理

chown username file
更改文件拥有者

chgrp groupname file
更改文件拥有组

chown username:groupname file
同时更改文件的拥有者和拥有组

chown|chgrp -R user|group dir
更改目录本身及目录中内容的拥有者或者拥有组
示例如图:
运维大法之Linux系统中的管理权限(二)设定普通权限的方法和系统默认权限设定以及文件用户用户组管理