Linux运维系统工程师系列06

本文发布时间: 2019-Mar-22
权限——权力的限制Linux里的文件和目录都是有一定的访问许可权限的。[[email protected] ~]# mkdir /priv[[email protected] ~]# cp /etc/passwd /priv/[[email protected] ~]# cd /priv/[[email protected] priv]# lltotal 4-rw-r--r--. 1 root root 1332 Oct 15 09:40 passwd-rw-r--r--:-:文件类型rw-r--r--:文件的权限1:链接数第一个root:是文件的属主第二个root:文件的所属组1332:文件的大小Oct 15 09:40:文件的最后修改时间(mtime)passwd:文件名查看文件类型[[email protected] priv]# file passwdpasswd: ASCII textlinux下文件类型:-:普通文件d:目录文件[[email protected] priv]# ll -d /priv/drwxr-xr-x. 2 root root 4096 Oct 15 09:42 /priv/c:字符设备 ——character[[email protected] priv]# ll /dev/tty7crw--w----. 1 root tty 4, 7 Oct 18 2013 /dev/tty7b:块设备 ——block 一般是硬盘设备等等[[email protected] priv]# ll /dev/sda2brw-rw----. 1 root disk 8, 2 Oct 9 16:33 /dev/sda2l:链接文件[[email protected] priv]# cd /var/[[email protected] var]# ll -d maillrwxrwxrwx. 1 root root 10 Oct 9 16:14 mail -> spool/mailp:管道文件——pipe[[email protected] var]# ll /var/spool/postfix/public/pickup -dprw--w--w-. 1 postfix postfix 0 Oct 18 2013 /var/spool/postfix/public/pickups:套接字文件——socket[[email protected] var]# ll /dev/logsrw-rw-rw-. 1 root root 0 Oct 9 16:33 /dev/logrw- r-- r--对于文件来说:1、用户分类如下:u —— 文件的所有者g —— 文件的所属组o —— 其他人a —— 所有人 (u,g,o)rw- r-- r--ugo2、权限的基本类型r —— 读权限w —— 写权限x —— 执行权限 (eXecute)[[email protected] priv]# useradd -G root groot[[email protected] priv]# useradd otheruser[[email protected] priv]# id rootuid=0(root) gid=0(root) groups=0(root)[[email protected] priv]# id grootuid=501(groot) gid=3004(groot) groups=3004(groot),0(root)[[email protected] priv]# id otheruseruid=502(otheruser) gid=502(otheruser) groups=502(otheruser)权限的设置1、chown ——change owner 修改文件的属主和属组——只修改文件的属主[[email protected] priv]# useradd usr4[[email protected] priv]# chown usr4 passwd[[email protected] priv]# ll passwd-rw-r--r--. 1 usr4 root 1332 Oct 15 09:40 passwd——只修改文件的属组[[email protected] priv]# chown .usr4 passwd[[email protected] priv]# ll passwd-rw-r--r--. 1 usr4 usr4 1332 Oct 15 09:40 passwd——同时修改文件的所有者和所属组[[email protected] priv]# useradd owner[[email protected] priv]# groupadd group[[email protected] priv]# chown owner.group passwd[[email protected] priv]# ll passwd-rw-r--r--. 1 owner group 1296 Oct 15 10:02 passwd——修改目录的所有者和所属组[[email protected] priv]# cd /[[email protected] /]# ll -d priv/drwxr-xr-x. 2 root root 4096 Oct 15 09:42 priv/[[email protected] /]# chown owner.group priv/[[email protected] /]# ll -d priv/drwxr-xr-x. 2 owner group 4096 Oct 15 09:42 priv/——递归修改目录的所有者和所属组 -R选项[[email protected] priv]# chown -R owner.group /priv[[email protected] priv]# ll -d /priv/drwxr-xr-x. 2 owner group 4096 Oct 15 09:42 /priv/[[email protected] priv]# lltotal 4-rw-r--r--. 1 owner group 0 Oct 15 09:42 a-rw-r--r--. 1 owner group 1296 Oct 15 10:02 passwd2、chmod ——change mode 修改文件和目录的权限——等值授权 =[[email protected] priv]# ll passwd-rw-r--r--. 1 owner group 1296 Oct 15 10:02 passwd[[email protected] priv]# chmod u=r passwd[[email protected] priv]# ll passwd-r--r--r--. 1 owner group 1296 Oct 15 10:02 passwd——增值授权 +[[email protected] priv]# ll passwd-r--r--r--. 1 owner group 1296 Oct 15 10:02 passwd[[email protected] priv]# chmod g+w passwd[[email protected] priv]# ll passwd-r--rw-r--. 1 owner group 1296 Oct 15 10:02 passwd——减值授权-[[email protected] priv]# chmod o-r passwd[[email protected] priv]# ll passwd-r--rw----. 1 owner group 1296 Oct 15 10:02 passwd三段同时操作[[email protected] priv]# ll passwd-r--rw----. 1 owner group 1296 Oct 15 10:02 passwd[[email protected] priv]# chmod a+x passwd[[email protected] priv]# ll passwd-r-xrwx--x. 1 owner group 1296 Oct 15 10:02 passwdchmod [u,g,o,a] [+-=] [rwx] filename[[email protected] priv]# chmod u=- passwd[[email protected] priv]# ll passwd----rwx--x. 1 owner group 1296 Oct 15 10:02 passwd数字权限:常用的一种方式权限对应的数字r —— 4w —— 2x —— 1- —— 0[[email protected] priv]# rw- r-- r--^C[[email protected] priv]# chmod 644 passwd[[email protected] priv]# ll passwd-rw-r--r--. 1 owner group 1296 Oct 15 10:02 passwdrw- r-- r--110 100 1006 4 4————————————————————————————练习:1、拷贝/etc/passwd文件到/priv目录下[[email protected] /]# mkdir /priv[[email protected] /]# cp /etc/passwd /priv/2、将文件的权限设置如下:所有者:读写执行所属组:读写其他人:读[[email protected] /]# chmod u=rwx,g=rw,o=r priv/passwd或者[[email protected] /]# chmod 764 priv/passwd[[email protected] /]# ll priv/passwd-rwxrw-r--. 1 root root 1495 Oct 15 11:06 priv/passwd3、新建用户owner和group[[email protected] /]# useradd owner[[email protected] /]# useradd group4、将/priv/passwd文件的所有者修改为group,所属组修改为owner[[email protected] /]# chown group.owner priv/passwd[[email protected] /]# ll priv/passwd-rwxrw-r--. 1 group owner 1495 Oct 15 11:06 priv/passwd5、在/priv目录下创建test目录[[email protected] /]# mkdir /priv/test6、将/priv目录的所有者改为owner[[email protected] /]# chown owner /priv/7、将/priv目录下的所有文件及目录的所属组修改为group[[email protected] /]# chown -R .group /priv/8、使用数字授权方式,将/priv/passwd文件的权限修改为如下要求:所有者:读写执行所属组和其他人:读和执行[[email protected] priv]# chmod 755 passwd[[email protected] priv]# ll passwd-rwxr-xr-x. 1 group group 1495 Oct 15 11:06 passwd111 101 1019、写出如下权限的数字权限:rw-r--r--:644rwxr-xr-x:755r--------:4001、文件的权限演示什么呢?就是文件有读、写、执行权限时候,能干点嘛?环境:[[email protected] ~]# mkdir /priv[[email protected] ~]# cd /priv/[[email protected] priv]# touch 1.txt[[email protected] priv]# touch 2.txt[[email protected] priv]# touch 4.txt[[email protected] priv]# echo hello > 1.txt[[email protected] priv]# echo hello > 2.txt[[email protected] priv]# echo hello > 4.txt[[email protected] priv]# chmod 641 1.txt[[email protected] priv]# chmod 642 2.txt[[email protected] priv]# chmod 644 4.txt[[email protected] priv]# lltotal 12-rw-r----x. 1 root root 6 Oct 15 11:36 1.txt-rw-r---w-. 1 root root 6 Oct 15 11:36 2.txt-rw-r--r--. 1 root root 6 Oct 15 11:36 4.txt执行权限:[[email protected] priv]$ ./1.txtbash: ./1.txt: Permission denied./表示的是当前路径对于文件:只有x权限,没有任何意义的,执行不了文件写权限:w[[email protected] priv]$ cat 2.txtcat: 2.txt: Permission denied[[email protected] priv]$ vim 2.txt有写权限说明我可以修改文件,但是无法查看文件,单独存在也是没有太大意义的。读权限:[[email protected] priv]$ cat 4.txthello[[email protected] priv]$ vim 4.txt可以看文件内容,但是无法修改。综上所述:r权限单独存在的话,你可以查看文件内容,但不允许修改w单独存在时,你看不到文件内容,但是可以强制修改内容,会覆盖原有内容,意义不大。x单独存在无意义chgrp:修改文件或者目录的所属组的[[email protected] /]# ll -d priv/drwxr-xr-x. 2 root root 4096 Oct 15 11:42 priv/[[email protected] /]# chgrp group priv/[[email protected] /]# ll -d priv/drwxr-xr-x. 2 root group 4096 Oct 15 11:42 priv/2、目录文件的权限1)单独只有一个[[email protected] /]# mkdir /priv[[email protected] /]# cd /priv/[[email protected] priv]# mkdir r[[email protected] priv]# mkdir w[[email protected] priv]# mkdir x[[email protected] priv]# cp /etc/passwd r/pr[[email protected] priv]# cp /etc/passwd w/pw[[email protected] priv]# cp /etc/passwd x/px[[email protected] priv]# chmod o=r r[[email protected] priv]# chmod o=w w[[email protected] priv]# chmod o=x x[[email protected] priv]# lltotal 12drwxr-xr--. 2 root root 4096 Oct 15 13:38 rdrwxr-x-w-. 2 root root 4096 Oct 15 13:38 wdrwxr-x--x. 2 root root 4096 Oct 15 13:39 x——目录的读权限[[email protected] ~]$ cd /priv/[[email protected] priv]$ ls rls: cannot access r/pr: Permission deniedpr只能看到有什么文件,但是不能修改也不能进入目录[[email protected] priv]$ cd r-bash: cd: r: Permission denied——目录的写权限[[email protected] priv]$ cd w-bash: cd: w: Permission denied[[email protected] priv]$ ls wls: cannot open directory w: Permission denied[[email protected] priv]$ rm w/pwrm: cannot remove `w/pw': Permission denied[[email protected] priv]$ touch w/pw1touch: cannot touch `w/pw1': Permission denied[[email protected] priv]$ vim w/pw1只有w权限,什么也做不了——目录的执行权限[[email protected] priv]$ ls xls: cannot open directory x: Permission denied[[email protected] priv]$ cd x[[email protected] x]$ pwd/priv/x有x权限,可以进入到目录里,但是不能查看目录内容2)目录权限的组合 rw rx wx[[email protected] priv]# mkdir rw[[email protected] priv]# mkdir rx[[email protected] priv]# mkdir wx[[email protected] priv]# chmod o=rx rx/[[email protected] priv]# chmod o=wx wx/[[email protected] priv]# chmod o=rw rw/[[email protected] priv]# cp /etc/passwd rx/prx[[email protected] priv]# cp /etc/passwd wx/pwx[[email protected] priv]# cp /etc/passwd rw/prw——目录的r-x权限:对于目录没有写权限,不能在下面创建,删除,修改文件。但是可以进入目录,可以查看目录内容。[[email protected] r]# su - owner[[email protected] ~]$ cd /priv/[[email protected] priv]$ cd rx[[email protected] rx]$ lsprx[[email protected] rx]$ rm prxrm: remove write-protected regular file `prx'? yrm: cannot remove `prx': Permission denied[[email protected] rx]$ touch prx1touch: cannot touch `prx1': Permission denied——目录的rw-权限:目录只有读写权限,什么也做不了,进不去,改不了[[email protected] priv]$ ls rwls: cannot access rw/prw: Permission deniedprw[[email protected] priv]$ cd rw/-bash: cd: rw/: Permission denied[[email protected] priv]$ rm rw/prwrm: cannot remove `rw/prw': Permission denied——目录的-wx权限:摸黑:可以进入目录,可以创建、删除文件,但是不能看到目录内容。[[email protected] priv]$ cd wx[[email protected] wx]$ lsls: cannot open directory .: Permission denied[[email protected] wx]$ rm pwxrm: remove write-protected regular file `pwx'? y[[email protected] wx]$ touch f1[[email protected] wx]$ lsls: cannot open directory .: Permission denied[[email protected] wx]$ rm f1passwd普通用户是可以改密码的。[[email protected] ~]# ll /etc/shadow----------. 1 root root 955 Oct 15 11:10 /etc/shadow引入新的权限:特殊权限原理:在做某些特定的操作的时候,能够临时获得最高权限;操作完成之后,权限被收回。有效uid和有效gid,euid,egideffective 有效的一般情况下,uid和euid是一样的uid是用来记录用户的操作行为的,euid是用来判断权限的特殊权限有三个:suid:sgid:sticky:suid——赋给可执行命令,作用:是让使用这个命令的用户,临时拥有这个命令的所有者的权限[[email protected] ~]# ll /usr/bin/passwd-rwsr-xr-x. 1 root root 25980 Feb 17 2012 /usr/bin/passwd[[email protected] priv]# cp /usr/bin/passwd /priv/[[email protected] priv]# ll passwd-rwxr-xr-x. 1 root root 25980 Oct 15 14:38 passwd[[email protected] priv]# chown owner passwd[[email protected] priv]# ls -l passwd-rwxr-xr-x. 1 owner root 25980 Oct 15 14:38 passwd[[email protected] priv]# chmod u+s passwd[[email protected] priv]# lltotal 28-rwsr-xr-x. 1 owner root 25980 Oct 15 14:38 passwd[[email protected] priv]# chmod u-x passwd[[email protected] priv]# ll passwd-rwSr-xr-x. 1 owner root 25980 Oct 15 14:38 passwdS——无效的suid权限s——有效的suid权限注意:添加suid权限时,一定要确定有执行权限。实验:[[email protected] ~]# useradd usuid[[email protected] ~]# useradd utsuid[[email protected] ~]# mkdir /suid[[email protected] ~]# chmod 777 /suid/[[email protected] ~]# cp /bin/vi /suid/[[email protected] ~]# chown usuid /suid/vi[[email protected] ~]# cd /suid/[[email protected] suid]# lltotal 704-rwxr-xr-x. 1 usuid root 720792 Oct 15 18:10 vi[[email protected] suid]# chmod u+s vi[[email protected] suid]# lltotal 704-rwsr-xr-x. 1 usuid root 720792 Oct 15 18:10 vi[[email protected] suid]# su - usuid[[email protected] ~]$ cd /suid/[[email protected] suid]$ lltotal 704-rwsr-xr-x. 1 usuid root 720792 Oct 15 18:10 vi[[email protected] suid]$ echo "hello i am usuid" > usuid_file[[email protected] suid]$ lltotal 708-rw-rw-r--. 1 usuid usuid 17 Oct 15 18:12 usuid_file-rwsr-xr-x. 1 usuid root 720792 Oct 15 18:10 vi[[email protected] suid]$ exitlogout[[email protected] suid]# su - utsuid[[email protected] ~]$ cd /suid/[[email protected] suid]$ lltotal 708-rw-rw-r--. 1 usuid usuid 17 Oct 15 18:12 usuid_file-rwsr-xr-x. 1 usuid root 720792 Oct 15 18:10 vi[[email protected] suid]$ ./vi usuid_file[[email protected] suid]$ cat usuid_filehello i am usuidhello i am utsuidsgid——赋给可执行命令,用户在使用该命令的时候,临时获得这个命令所属组的权限实验:[[email protected] ~]# useradd ugid[[email protected] ~]# useradd utgid[[email protected] ~]# mkdir /sgid[[email protected] ~]# chmod 777 /sgid/[[email protected] ~]# cp /bin/vi /sgid/ugid_vi[[email protected] ~]# cd /sgid/[[email protected] sgid]# lltotal 704-rwxr-xr-x. 1 root root 720792 Oct 15 18:18 ugid_vi[[email protected] sgid]# chgrp ugid ugid_vi[[email protected] sgid]# lltotal 704-rwxr-xr-x. 1 root ugid 720792 Oct 15 18:18 ugid_vi[[email protected] sgid]# chmod g+s ugid_vi[[email protected] sgid]# lltotal 704-rwxr-sr-x. 1 root ugid 720792 Oct 15 18:18 ugid_vi[[email protected] sgid]# su - ugid[[email protected] ~]$ cd /sgid/[[email protected] sgid]$ lltotal 704-rwxr-sr-x. 1 root ugid 720792 Oct 15 18:18 ugid_vi[[email protected] sgid]$ echo "hello i am ugid" > ugid_file[[email protected] sgid]$ lltotal 708-rw-rw-r--. 1 ugid ugid 16 Oct 15 18:22 ugid_file-rwxr-sr-x. 1 root ugid 720792 Oct 15 18:18 ugid_vi[[email protected] sgid]$ exitlogout[[email protected] sgid]# su - utgid[[email protected] ~]$ cd /sgid/[[email protected] sgid]$ lltotal 708-rw-rw-r--. 1 ugid ugid 16 Oct 15 18:22 ugid_file-rwxr-sr-x. 1 root ugid 720792 Oct 15 18:18 ugid_vi[[email protected] sgid]$ ./ugid_vi ugid_file[[email protected] sgid]$ lltotal 708-rw-rw-r--. 1 ugid ugid 33 Oct 15 18:22 ugid_file-rwxr-sr-x. 1 root ugid 720792 Oct 15 18:18 ugid_vi[[email protected] sgid]$ cat ugid_filehello i am ugidhello i am utgidsticky——一般是在所有用户都有全部权限的目录用来限制用户,不能随意的更改或者删除别人的文件[[email protected] ~]# ll -d /tmp/drwxrwxrwt. 19 root root 4096 Oct 15 14:03 /tmp/[[email protected] ~]# mkdir /new[[email protected] ~]# chmod 777 /new[[email protected] ~]# useradd p1[[email protected] ~]# useradd p2[[email protected] ~]# su - p1[[email protected] ~]$ cd /new[[email protected] new]$ touch p1-file[[email protected] new]$ touch p1-file1在另一个标签[[email protected] ~]# su - p2[[email protected] ~]$ cd /new[[email protected] new]$ rm p1-file 可以删除[[email protected] new]$ vim p1-file1 可以修改添加t权限[[email protected] ~]# chmod o+t /new[[email protected] ~]# su - p2[[email protected] ~]$ cd /new[[email protected] new]$ rm p1-file 不可以删除了sticky权限:用户只能修改属于自己的文件,而不能修改其他人的文件。特殊权限的数字表示rwsrwsr-t:7775suid sgid sticky rwx r-x r-x1 1 1suid:4sgid:2sticky:1475527551755场景描述:[[email protected] ~]# useradd acl1[[email protected] ~]# useradd acl2[[email protected] ~]# mkdir /test[[email protected] ~]# cd /test/[[email protected] test]# echo happy > root_file[[email protected] test]# chmod 757 /test[[email protected] test]# lltotal 4-rw-r--r--. 1 root root 6 Oct 16 10:18 root_file[[email protected] test]# acl1 rw[[email protected] test]# acl2 rx对于ugo模式的权限,用户acl1和acl2对于文件root_file来说都是其他人,如果要针对他们做不同的对待,解决不了出现了ACL权限ACL——Access Control List 访问控制列表可以针对用户,针对组[[email protected] test]# mount/dev/sda2 on / type ext4 (rw)要支持ACL,分区需要激活acl功能开启分区的acl功能[[email protected] test]# mount -o acl,remount /dev/sda2只查看/dev/sda2分区的挂载情况[[email protected] test]# mount | grep sda2/dev/sda2 on / type ext4 (rw,acl)两个命令:setfacl:设置文件的acl访问权限getfacl:获取文件的acl访问权限设置acl1用户对root_file可读写# setfacl-m :--modify 修改u:用户名:权限或者g:组名:权限root_file :文件名[[email protected] test]# setfacl -m u:acl1:rw root_file[[email protected] test]# getfacl root_file# file: root_file# owner: root# group: rootuser::rw-user:acl1:rw-group::r--mask::rw-other::r--[[email protected] test]# setfacl -m u:acl2:rx root_file[[email protected] test]# getfacl root_file# file: root_file# owner: root# group: rootuser::rw-user:acl1:rw-user:acl2:r-xgroup::r--mask::rwxother::r--验证:[[email protected] test]# su - acl1[[email protected] ~]$ cd /test/[[email protected] test]$ lltotal 8-rw-rwxr--+ 1 root root 6 Oct 16 10:18 root_file[[email protected] test]$ cat root_filehappy[[email protected] test]$ echo acl1 >> root_file[[email protected] test]$ cat root_filehappyacl1[[email protected] test]$ exitlogout[[email protected] test]# su - acl2[[email protected] ~]$ cd /test/[[email protected] test]$ lltotal 8-rw-rwxr--+ 1 root root 11 Oct 16 10:33 root_file[[email protected] test]$ cat root_filehappyacl1[[email protected] test]$ echo acl2 >> root_file-bash: root_file: Permission denied设置了acl权限后,在权限位置出现一个“+”号[[email protected] test]$ ll-rw-rwxr--+ 1 root root 11 Oct 16 10:33 root_file——移除单个用户的acl访问控制列表[[email protected] test]# setfacl -x u:acl1 root_file[[email protected] test]# getfacl root_file# file: root_file# owner: root# group: rootuser::rw-user:acl2:r-xgroup::r--mask::r-xother::r--——移除全部列表 -b[[email protected] test]# setfacl -m u:acl1:rw root_file[[email protected] test]# getfacl root_file# file: root_file# owner: root# group: rootuser::rw-user:acl1:rw-user:acl2:r-xgroup::r--mask::rwxother::r--[[email protected] test]# setfacl -b root_file[[email protected] test]# getfacl root_file# file: root_file# owner: root# group: rootuser::rw-group::r--other::r--练习:1、添加三个用户facl1,facl2,facl32、创建/test/acl目录,并将/etc/group文件拷贝到/test/acl目录下,同时重命名为grp3、设置grp文件facl1用户可以读写,facl2用户可读不可写,facl3用户无法操作,分别切换到三个用户进行权限的验证4、删除facl1用户的访问控制列表,使用getfacl验证5、删除所有用户的访问控制列表,使用getfacl验证6、修改facl2用户的主组为facl17、设置grp文件能够被facl1组的用户读写,facl3组的用户只读,并验证权限setfacl -m g:facl1:rw /test/acl/grpsetfacl -m g:facl3:r /test/acl/grpsetfacl -m g:facl1:rw,g:facl3:r /test/acl/grp8、删除facl1组的访问控制列表,并用getfacl验证对同类用户区别对待权限的掩码查看用户的umask[[email protected] root]# umask0022umask决定了你创建文件或者目录时候的默认权限[[email protected] tmp]# mkdir /tmp/root[[email protected] tmp]# ll -d rootdrwxr-xr-x. 2 root root 4096 Oct 16 11:43 root[[email protected] tmp]# touch /tmp/root/froot[[email protected] tmp]# ll roottotal 0-rw-r--r--. 1 root root 0 Oct 16 11:43 froot[[email protected] root]# useradd umask[[email protected] root]# su - umask[[email protected] ~]$ umask0002[[email protected] ~]$ mkdir udir[[email protected] ~]$ touch udir/ufile[[email protected] ~]$ lltotal 4drwxrwxr-x. 2 umask umask 4096 Oct 16 11:47 udir[[email protected] ~]$ ll udir/ufile-rw-rw-r--. 1 umask umask 0 Oct 16 11:47 udir/ufile为什么默认权限是这样呢?root:0022umask:0002目录最大权限:777文件最大权限:666755 + 022 = 777目录的默认权限=目录的最大权限(777)-umask文件的默认权限=文件的最大权限(666)-umask修改用户的umask:[[email protected] ~]$ umask 0022[[email protected] ~]$ umask0022umask为0003,创建的文件和目录的权限时什么?目录文件rwx rwx rwx rw- rw- rw---- --- -wx --- --- -wx774664大家不要将umask设置为奇数的。配置文件中定义的/etc/profileif [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; thenumask 002elseumask 022fi[[email protected] root]# id -gn 显示主组名字root[[email protected] root]# id -un显示用户名字root场景:有的时候我希望文件只能往里追加东西,或者呢就压根不让更改文件内容等。引入一个新的权限——文件系统权限,也叫隐藏权限,附加权限不是所有的文件系统都支持文件系统权限。相关的命令:lsattr:查看chattr:修改、设置 change attribute(属性)文件系统权限对root也是生效的。man chattrThe letters ‘acdeijstuADST’ select the new attributes for the files:append only (a), compressed (c), no dump (d), extent format (e),immutable (i), data journalling (j), secure deletion (s), no tail-merg-ing (t), undeletable (u), no atime updates (A), synchronous directoryupdates (D), synchronous updates (S), and top of directory hierarchy(T).a -- append only 只追加c -- compressed 压缩i -- immutable 免疫的,不可修改s -- secure delete 安全删除:用0覆盖原有内容,但是不保证能够完全删除d -- no dump 不备份e -- extent format 扩展格式,基本不使用了j -- data journalling 记录日志u -- undeletable 不可以删除S -- synchronous updates 同步更新D -- synchronous directory updates同步目录更新A -- no atime updates 不更新访问时间记住两个就可以了,a,i——设置文件的文件系统权限[[email protected] ~]# cd /test/[[email protected] test]# echo "i am super user" > fa[[email protected] test]# lltotal 4-rw-r--r--. 1 root root 16 Oct 16 13:51 fa[[email protected] test]# chattr +a fa[[email protected] test]# lsattr fa-----a-------e- fa[[email protected] test]# cat fai am super user[[email protected] test]# echo hello > fabash: fa: Operation not permitted[[email protected] test]# rm farm: remove regular file `fa'? yrm: cannot remove `fa': Operation not permitted[[email protected] test]# vim fa[[email protected] test]# echo hello >> fa[[email protected] test]# lltotal 12-rw-r--r--. 1 root root 22 Oct 16 13:54 fa-rw-r--r--. 1 root root 16 Oct 16 13:54 fa~-rw-r--r--. 1 root root 16 Oct 16 13:54 fz~[[email protected] test]# cat fai am super userhello用处:一般a是加在日志文件上。——取消文件的文件系统权限[[email protected] test]# chattr -a fa[[email protected] test]# lsattr fa-------------e- fa[[email protected] test]# rm farm: remove regular file `fa'? y[[email protected] test]# ls fals: cannot access fa: No such file or directoryi:不可以修改文件[[email protected] test]# echo root > fb[[email protected] test]# chattr +i fb[[email protected] test]# lsattr fb----i--------e- fb[[email protected] test]# rm fbrm: remove regular file `fb'? yrm: cannot remove `fb': Operation not permitted[[email protected] test]# echo hello > fbbash: fb: Permission denied[[email protected] test]# echo hello >> fbbash: fb: Permission denied[[email protected] test]# vi fb[[email protected] test]# cat fbroot[[email protected] test]# chattr -i fb[[email protected] test]# lsattr fb-------------e- fbs:安全删除[[email protected] test]# chattr +s fb[[email protected] test]# lsattr fbs------------e- fb练习:1、在/test下创建文件afile,bfile,cfile,分别将hello写入文件2、设置afile只能追加内容,不能删除,不能修改3、设置bfile文件不能够修改4、假设在/test下存在一个文件a,你无法删除它,那么可能原因是什么?权限不足,a,i5、假设在/test下存在有一个文件,你只能使用>>向里面写东西,文件也不能删除,可能的原因?a文件的权限都谁可以改?1、root肯定可以改的2、文件的所有者可以改[[email protected] tmp]# su - lily[[email protected] ~]$ touch lilyf[[email protected] ~]$ lltotal 4drwxr-xr-x. 2 lily dev 4096 Oct 16 11:42 dlily-rw-r--r--. 1 lily dev 0 Oct 16 14:21 lilyf[[email protected] ~]$ chmod 755 lilyf[[email protected] ~]$ lltotal 4drwxr-xr-x. 2 lily dev 4096 Oct 16 11:42 dlily-rwxr-xr-x. 1 lily dev 0 Oct 16 14:21 lilyfchmod +[rwx] filenamechmod+wroot:不会全部都增加w权限,只给所有者加,使用数字权限没有这问题[[email protected] ~]# mkdir /t1[[email protected] ~]# cd /t1[[email protected] t1]# cp /etc/passwd pass[[email protected] t1]# lltotal 4-rw-r--r--. 1 root root 2226 Oct 16 14:21 pass[[email protected] t1]# chmod 000 pass[[email protected] t1]# lltotal 4----------. 1 root root 2226 Oct 16 14:21 pass[[email protected] t1]# chmod +r pass[[email protected] t1]# lltotal 4-r--r--r--. 1 root root 2226 Oct 16 14:21 pass[[email protected] t1]# chmod +w pass[[email protected] t1]# lltotal 4-rw-r--r--. 1 root root 2226 Oct 16 14:21 pass普通用户:会给所有者权限和所属组权限加上w权限[[email protected] t1]# su - umask[[email protected] ~]$ touch ab[[email protected] ~]$ lltotal 4-rw-rw-r--. 1 umask umask 0 Oct 16 14:27 abdrwxrwxr-x. 2 umask umask 4096 Oct 16 11:47 udir[[email protected] ~]$ chmod 000 ab[[email protected] ~]$ chmod +w ab[[email protected] ~]$ lltotal 4--w--w----. 1 umask umask 0 Oct 16 14:27 ab


(以上内容不代表本站观点。)
---------------------------------
本网站以及域名有仲裁协议。
本網站以及域名有仲裁協議。

2020-Jul-13 01:14am
栏目列表