一、基本权限UGO 1、设置权限的两个方面 2、权限的三种类 对象
* 属主:u(user)
* 属组:g(group)
* 其他人:o(other)
* 特殊对象:所有人:a(all)(u+g+o) 3、权限的三种 类型(八进制)
* 读:r=4
* 写:w=2
* 执行:x=1 4、 设置权限 4.1使用符号 chmod(change mode)命令: 可以修改 u g o 的  r-4   w-2  x-1
语法:  chmod           u+r                 1.txt     命令      对象加减权限      文件或目录
注意:这是在对文件授权;在对文件夹授权时需要 加   -r [root@localhost ~]# cd   /tmp/ [root@localhost
tmp]# //先进入到(tmp)临时目录中去 [root@localhost tmp]# touch file1 //创建文件file1
[root@localhost tmp]# ls -l [root@localhost tmp]# ll file1 - rw-   r--   
r--.        1       root      root        0                  属主 属组 其他人   链接   
 属主      属组      大小 7月  27    15:14      file1      创建时间          文件名
rwx:表示拥有所有权限 要求1:给file授予属主读的权限,没有写和执行 [root@localhost ~]# chmod u=r file1
[root@localhost ~]# ls -l file1 -r--r--r--. 1 root root 0 7月  27 15:57 file1
要求2:给file授予属组读、写和执行的权限 [root@localhost ~]# chmod g=rwx file1 [root@localhost
~]# ls -l file1 -r--rwxr--. 1 root root 0 7月  27 15:57 file1
要求3:给file授予其他用户没有读写和执行的权限 [root@localhost ~]# chmod o=  file1 [root@localhost
~]# ls -l file1 -r--rwx---. 1 root root 0 7月  27 15:57 file1 [root@localhost
tmp]# ls -l -d /tmp/ drwxrwxrwt. 179 root root 16384 7月  27 16:10 /tmp/
用数字修改权限 1:执行      2:写       4:读 [root@localhost tmp]# chmod 777 /tmp/file1
[root@localhost tmp]# ls -l /tmp/file1 -rwxrwxrwx. 1 root root 0 7月  27 15:14
/tmp/file1 —————————————————————— chown命令(change owner) 可以修改用户和组
[root@localhost tmp]# chown  user01.hr /tmp/file1
                                                   用户     组 [root@localhost
tmp]# ls -l /tmp/file1 -rwxrwxrwx. 1 user01 hr 0 7月  27 15:14 /tmp/file1
chogrep:只能修改组 注意:以上三种修改方式均可在文件中适用 但是在文件中的设置权限不会添加到子文件下的文件中 如需添加在命令中加     -r(递归)
案例:[root@localhost tmp]#  mkdir /temp/hr mkdir: 无法创建目录"/temp/hr": 没有那个文件或目录
[root@localhost tmp]#  mkdir /tmp/hr [root@localhost tmp]# ls -d /tmp/hr
/tmp/hr [root@localhost tmp]# ls -d /tmp/hr -l d rwx r-x r-x. 2 root root 6
7月  27 17:07 /tmp/hr //查看修改前 [root@localhost tmp]# chmod 770 /temp/hr
//给r和g全部权限  给o 没有任何权限 [root@localhost tmp]# ls -l -d   /tmp/hr //查看修改后
drwxrwx---. 2 root root 6 7月  27 17:07 /tmp/hr 二、ACL文件权限管理
特点:可以设置不同的用户,不同的基本权限(r,w,x)对象数量不同; UGO:只能一个用户,一个组,或者其他人 语法:setfacl(设置文件访问控制列表)
setfacl  -m  u(user)/g(group)/o(other):hr:rwx /文件路径             设置           
         对象      :对象名:权限 root@localhost tmp]# touch /home/test //创建文件
[root@localhost tmp]# ls /home
1  AAA  BBB  test  user01  user02  user03  user04  yps [root@localhost tmp]#
ls -l /home/test -rw-r--r--. 1 root root 0 7月  27 20:17 /home/test //查看文件
1、查看文件权限 [root@localhost tmp]# getfacl /home/test getfacl: Removing leading
'/' from absolute path names # file: home/test # owner: root # group: root
user::rw- group::r-- other::r-- 2、设置用户权限 注意:设置之前一定要先创建用户 [root@localhost
tmp]# useradd user01 [root@localhost tmp]# useradd user02
_________________________________________________ [root@localhost tmp]#
setfacl  -m u:user01:rw /home/test [root@localhost tmp]# setfacl  -m u:user02:
- /home/test [root@localhost tmp]# getfacl  /home/test getfacl: Removing
leading '/' from absolute path names # file: home/test # owner: root #
group: root user::rw- user:user01:rw- user:user02:--- group::r-- mask::rw-
other::r-- 3.删除 [root@localhost tmp]# setfacl -x u:user01 /home/test
//删除用户访问权限(注意:不用写权限(r,w,x)) [root@localhost tmp]# getfacl /home/test getfacl:
Removing leading '/' from absolute path names # file: home/test # owner: root
# group: root user::rw- user:user02:--- group::r-- mask::r-- other::r--
建立:-m   ;删除:-x  ;清除干净:-b   ; 三、特殊权限(了解) 例如:不小心删除了文件怎么办 1、特殊位 suid
功能:使调用文件的用户,临时具备属主能力 [root@localhost ~]# chmod u+s(suid) /home/test
[root@localhost ~]# ls  -l  /home/test -rwsrw----+ 1 user01 hr 0 7月  27 20:17
/home/test 2、文件属性 chattr    -i(不可以被删除) wghtsch - n1‘ getfacl /tmp/file1
wghtsch - n1‘ lsattr /tmp/file1 3、进程掩码 umask :掩码与权限相反 掩码0022+权限0755=0777
文件的默认权限为644: 目的:系统为例保护自己,在新建的文件上取消了执行权限 [root@localhost ~]# umask 0022
[root@localhost ~]# mkdir yangpanshaui [root@localhost ~]# touch
yangpanshauifile [root@localhost ~]# ls -dl yangpanshaui  yangpanshauifile
drwxr-xr-x. 2 root root 6 7月  28 11:11 yangpanshaui -rw-r--r--. 1 root root 0
7月  28 11:11 yangpanshauifile

技术
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信