南京培训网站建设,常用的网页编辑工具有哪些,做彩票网站收费标准,快速搭建网站wordpress权限管理
文件的权限针对三类对象进行定义#xff1a;
owner属主#xff0c;缩写ugroup属组#xff0c;缩写gother其他#xff0c;缩写o
1、文件的一般权限 #xff08;1#xff09;r,w,x的作用及含义#xff1a;
权限对文件影响对目录影响r#xff08;read#xf…权限管理
文件的权限针对三类对象进行定义
owner属主缩写ugroup属组缩写gother其他缩写o
1、文件的一般权限 1r,w,x的作用及含义
权限对文件影响对目录影响rread读可以读取文件内容 可以列出目录的内容即目录下的文件的文件名 wwrite写 可以更改文 件的内容 可以创建或者删除目录中的任一文件只有w权限无法创建删除文件需要和x权限一起使用 xexecute执行 可作为可执行文件 可以切换到目录 -无没有权限PSroot账户不受文件权限的读写限制执行权限受限制 2相应二进制可表示对应权限 所属者/所属组/其他用户权限的字符表示 二进制表示 八进制表示 ---0000--x0011-w-0102-wx0113r--1004r-x1015rw-1106rwx1117
如图 3常见普通权限组合
目录r-xrwx---文件文本文件r-xrw-rwxr-----
2、修改权限
1修改文件或目录的权限 --- chmod
格式1chmod [选项] [ugoa][-][rwx] 文件或目录..格式2chmod [选项] nnn 文件或目录... 常用选项u g o a 权限设置所针对的用户类别。 u(user)表示文件或目录的属主(所有者)g(group)表示属组内的用户o(others)表示其他用户a(all)表示所有用户(即ugo) 或 - 或 设置权限的操作动作代表添加某个权限-代表取消某个权限表示只赋予给定的权限并取消原有的权限 rwx 用字符形式表示的所设置的权限可以是其中一个字母或组合 nnn 用三位八进制数字表示的权限
例1修改文件a1的权限
[roottianqinwei test]# ll --- 查看文件权限
total 0
-rw-r--r--. 1 root root 0 Mar 6 17:45 a1
[roottianqinwei test]# chmod o-r a1 --- 对其他用户去掉可读权限
[roottianqinwei test]# ll a1
-rw-r-----. 1 root root 0 Mar 6 17:45 a1
[roottianqinwei test]# chmod g--- a1 --- 将所属组权限改为---
[roottianqinwei test]# ll a1
-rw-------. 1 root root 0 Mar 6 17:45 a1
[roottianqinwei test]# chmod 640 a1 --- 用数字来修改权限参考上方二进制转为八进制
[roottianqinwei test]# ll a1
-rw-r-----. 1 root root 0 Mar 6 17:45 a1
[studenttianqinwei test]$ cat a1 --- 验证普通用户对a1没有权限
cat: a1: Permission denied
[roottianqinwei ~]# ll -d /root/
drwxrwxrwx. 16 root root 4096 Mar 6 18:18 /root/
[roottianqinwei test]# chmod a-w /root/ --- 将/root/用户所属组其他用户的写权限全都修改
[roottianqinwei test]# ll -d /root/
dr-xr-xr-x. 16 root root 4096 Mar 6 18:18 /root/
例2将文件a2改为所属组和其他用户可读可写
[roottianqinwei test]# chmod grw-,orw- a2 --- 中间部分命令用逗号隔开系统会把o部分认为是文件名称所以用空格分隔会报错
[roottianqinwei test]# ll a2
-rw-rw-rw-. 1 root root 0 Mar 6 17:45 a2
[studenttianqinwei test]$ cat a2 --- 验证可对文件进行可读操作
azsdfgarhae5rhjndtgnsrt6jnjmrfsngxer5dyhusrtn
2修改文件或目录的属主和属组
1 chown可同时修改属主和属组
格式chown [选项] 新属主[:[新属组]] 文件或目录…
例修改文件a2所属主所属组
[roottianqinwei test]# ll a2
-rw-rw-rw-. 1 root root 46 Mar 6 18:05 a2
[roottianqinwei test]# chown student a2 --- 修改所属主
[roottianqinwei test]# ll a2
-rw-rw-rw-. 1 student root 46 Mar 6 18:05 a2
[roottianqinwei test]# chown :student a2 --- 修改所属组
[roottianqinwei test]# ll a2
-rw-rw-rw-. 1 student student 46 Mar 6 18:05 a2
[roottianqinwei test]# chown root:root a2 --- 同时修改所属主和所属组
[roottianqinwei test]# ll a2
-rw-rw-rw-. 1 root root 46 Mar 6 18:05 a2
2 chgrp只能修改文件的所属组
格式chgrp [选项] [新属组] 文件或目录...
例修改文件a3所属组
[roottianqinwei test]# ll a3
-rw-r--r--. 1 root root 39 Mar 6 18:05 a3
[roottianqinwei test]# chgrp student a3
[roottianqinwei test]# ll a3
-rw-r--r--. 1 root student 39 Mar 6 18:05 a3
3例student用户可读可写a3其他用户都不可进行操作
[roottianqinwei test]# ll a3 --- 查看a3文件的权限以及所属主和组
-rw-r--r--. 1 root student 39 Mar 6 18:05 a3
[roottianqinwei test]# chmod 600 a3 --- 将文件所属组和其他用户的所有权限取消
[roottianqinwei test]# ll a3
-rw-------. 1 root student 39 Mar 6 18:05 a3
[roottianqinwei test]# chown student:root a3 --- 将文件的所属主改为student所属组改为root
[roottianqinwei test]# ll a3
-rw-------. 1 student root 39 Mar 6 18:05 a3
则此时文件仅可由student用户进行读写
3、文件的特殊权限
1SUIDus权限
1 含义为了让一般用户在执行某些程序的时候 在程序的运行期间 暂时获得该程序文件所属者的权限 如
[roottianqinwei test]# ll /usr/bin/passwd
--- 当用户使用passwd命令的时候短暂拥有该命令所有者root的权限
所以此时普通用户就可在shadow上进行操作修改且只能在二进制执行文件上使用
-rwsr-xr-x. 1 root root 34512 Aug 13 2018 /usr/bin/passwd
[roottianqinwei test]# ll /etc/shadow
----------. 1 root root 1309 Oct 21 08:51 /etc/shadow student 用户在执行 passwd 修改自己的密码时 其修改的密码 最终是需要保存到 /etc/shadow 这个文件中而这个文件的权限是 --------- 它的拥有者是 root 也只有root 可以“ 强制” 存储 其他用户连看都不行。可student 去执行 passwd /usr/bin/passwd) 却可以更新自己的密码 2 例将文件a1和a2得到权限修改为SUIDus
[roottianqinwei test]# ll
total 12
-rwxrwxrwx. 1 root root 241 Mar 6 18:05 a1
-rw-rw-rw-. 1 root root 46 Mar 6 18:05 a2
[roottianqinwei test]# chmod us a1 --- 将用户权限修改为us
[roottianqinwei test]# chmod us a2
[roottianqinwei test]# ll
total 12
-rwsrwxrwx. 1 root root 241 Mar 6 18:05 a1 --- 若该文件是可执行文件显示为s
-rwSrw-rw-. 1 root root 46 Mar 6 18:05 a2 --- 若改文件是不可执行文件显示为S 有 s 权限的存在当 s权限在拥有者的权限位上时 即如 -rwsr-xr-x 这样时 称为SUID 。SUID 即 Set UID UID 指的是拥有者的的 ID 而这个程序 (/usr/bin/passwd) 的拥有者为root) PS
SUID仅对二进制文件有效执行过程中调用者暂时获得该文件所有者权限该权限只在执行过程中有效
2SGIDgs权限
1 作用
文件如果 SGID 设置在二进制文件上则不论用户是谁在执行该程序时程序所属组将会变成该程序文件的所属组目录若SGID设置在A目录上则A目录内所建立的文件和目录的所属组将会是A目录的所属组
2 例将用户haha放入student组中在该组中将权限更改为SGID使得haha用户也可创建或删除文件
[roottianqinwei test]# useradd haha --- 添加用户haha
[roottianqinwei test]# gpasswd -a haha student --- 添加用户haha到student组中
Adding user haha to group student
[roottianqinwei test]# tail -2 /etc/group
student:x:1000:haha
haha:x:1001:
[roottianqinwei test]# ll -d /test
drwxr-xr-x. 2 root root 36 Mar 6 18:05 /test
[roottianqinwei test]# chown :student /test --- 将目录/test所属组改为student
[roottianqinwei test]# ll -d /test
drwxr-xr-x. 2 root student 36 Mar 6 18:05 /test
[roottianqinwei test]# chmod gs /test --- gs的效果只要在所属组中的用户都可在该目录下创建或删除文件操作的文件都在student这个组中
[roottianqinwei test]# chmod gw /test --- 给所属组添加可写权限
[roottianqinwei test]# ll -d /test
drwxrwsr-x. 2 root student 36 Mar 6 18:05 /test
验证
[studenttianqinwei test]$ touch ss
[hahatianqinwei test]$ touch dd
[roottianqinwei test]# ll
-rw-rw-r--. 1 haha student 0 Mar 6 20:07 dd --- haha用户创建出的文件所属主为haha所属组为student
-rw-rw-r--. 1 student student 0 Mar 6 20:07 ss --- student用户创建出的文件所属主为student,所属组为student
3Sticky Bit--SBitot只针对目录有效 对文件没有效果
1 含义具有 SBit 的目录下 用户若在该目录下具有 w 及 x 权限 则当用户在该目录下建立文件或目录时 只有文件拥有者与 root 才有权力删除
2 例将目录 /test 其他用户的权限更改为SBit
[roottianqinwei test]# ll -d /test
drwxrwsrwx. 2 root student 56 Mar 6 20:07 /test
[roottianqinwei test]# chmod ot /test
[roottianqinwei test]# ll -d /test
drwxrwsrwt. 2 root student 56 Mar 6 20:07 /test --- o用户在该目录下只可针对自己创建的文件进行“删除/重命名/移动”操作4、ACL权限
1含义若想指定一个用户想访问一个组中的文件而该组中无此用户则可用ACL权限指定该用户赋予其相应权限。
2命令
1 查看权限getfacl [文件名]
2 设定权限setfacl 选项 文件名
常用选项-m 设定 ACL 权限。如果是给予用户 ACL 权限则使用 u:用户名:权限 格式赋予如果是给予组 ACL 权限则使用 g:组名:权限 格式赋予 -x 删除指定的ACL权限-b删除所有的ACL权限-d设定默认ACL权限。只对目录生效目录中新建立的文件有此默认权限-k删除默认ACL权限-R递归设定ACL权限。指设定的ACL权限会对子目录下所有文件生效
例文件权限为rwx rw- ---文件所属主为wu文件所属组为csa。若让组外用户xixi对此目录中文件可读可写且不让其他用户拥有权限命令为setfacl -m u:xixi:rw- cs
5、umask权限掩码
1作用设置新建文件或目录的默认权限
2默认umask 在Linux系统中当用户创建一个新的文件或目录时系统都会为新建的文件或目录分配默认的权限该默认权限与umask值有关其具体关系是 新建文件的默认权限0666-umask值新建目录的默认权限0777-umask值[roottianqinwei test]# umask --- 查看默认umask值
00223例umask默认值为033则对应的文件和目录的默认权限是什么 则文件对应默认权限是644目录对应默认权限为744