2.14文件或目录权限chmod
[root@centos-01 ~]# ls -l
总用量 8
-rw-------. 1 root root 1422 12月 12 23:44 anaconda-ks.cfg
-rw-r--r--. 1 root root 1652 12月 13 19:37 initial-setup-ks.cfg
第一列第二位开始往后看九位
一个文件有三个权限位 九位分成了三段
rwxr-xr-x 前三位代表所有者 中间三位所属组 后三位代表其他用户
r 读 w 写 x 执行
权限可以用数字表示
r=4 w=2 x=1 rwx=7 rw=6 --x-1 rw-r--r--=644 rw-r-xr-x=655
[root@centos-01 ~]# ls -ld /root/.ssh
drwx------. 2 root root 29 12月 15 11:17 /root/.ssh
[root@centos-01 ~]# ls -l /tmp/
总用量 16
-rw-r--r--. 1 root root 6023 12月 13 19:37 anaconda.log
drwxr-xr-x. 2 root root 19 12月 13 19:16 hsperfdata_root
-rw-r--r--. 1 root root 0 12月 13 19:29 ifcfg.log
-rwx------. 1 root root 836 12月 12 23:44 ks-script-94AA5j
-rw-r--r--. 1 root root 0 12月 13 19:29 packaging.log
-rw-r--r--. 1 root root 0 12月 13 19:29 program.log
-rw-r--r--. 1 root root 0 12月 13 19:29 sensitive-info.log
-rw-r--r--. 1 root root 0 12月 13 19:29 storage.log
九位后面都有个点,表示这个文件受制于selinux
如果要想把目录下面的子目录还有子文件全部一次性的批量的更改他们的权限 chmod 后面加 -R
#chmod u=rwx,g=r,o-r aming2
u 所有者
g 所属组
o 其他用户
#chmod a+x aming2
a 代表所有的意思 会把所有的 u g o 都加上x权限
2.15更改所有者和所属组chown
-
chown命令
更改目录或文件的所有者以及所属组。
chown=change owner
语法:
chown [-R] 账户名 filename 更改所有者
chown [-R] 账户名:组名 filename 更改所属组
选项: -R的作用是级联更改
eg:[root@centos-01 ~]# ls -l /tmp/yum.log //查看yum.log的所有者 // -rw-------. 1 root user1 0 12月 12 23:38 /tmp/yum.log [root@centos-01 ~]# chown aming /tmp/yum.log //更改文件的所有 者为aming// [root@centos-01 ~]# ! ls
ls -l /tmp/yum.log
-rw-------.1 aming root 0 12月 12 23:38 /tmp/yum.log -
chgrp 更改所属组
[root@centos-01 ~]# charp user1 /tmp/yum.log
[root@centos-01 ~]#! ls
ls -l /tmp/yum.log
-rw-------.1 aming user1 0 12月 12 23:38 /tmp/yum.log#chown username :group filename //可以一次性的更改所有者和所属组//
[root@centos-01 ~]# chown user1:aming /tmp/yum.log
[root@centos-01 ~]#! ls
ls -l /tmp/yum.log
-rw-------.1 user1 aming 0 12月 12 23:38 /tmp/yum.log
#chown -R username :group filename //R可以继承更改他下面的文件//
2.16umask
[root@centos-01 ~]# touch 11.txt //创建一个文件//
[root@centos-01 ~]# ls -l 11.txt //查看文件的权限//
-rw-r--r--. 1 root root 0 12月 12 23:39 11.txt //权限是644//
[root@centos-01 ~]# mkdir 123 //创建一个目录//
[root@centos-01 ~]# ls -ld 123 //查看目录的权限//
drwxr-xr-x. 2 root root 6 12月 12 23:39 123 //权限是755//
[root@centos-01 ~]# umask
0022 // 系统root用户的 umask值//
[root@centos-01 ~]# umask 002 //修改umask值为 002//
[root@centos-01 ~]# umask //查看umask值//
0002
umask值改变后创建文件和目录的权限
[root@centos-01 ~]# touch 3.txt //创建一个文件//
[root@centos-01 ~]# ls -l 3.txt //查看文件权限//
-rw-rw-r--. 1 root root 0 12月 12 23:39 3.txt //权限是664//
[root@centos-01 ~]# mkdir 234 //创建一个目录//
[root@centos-01 ~]# ls -ld 234 //查看目录权限//
drwxrwxr-x. 2 root root 6 12月 12 23:39 234 //权限是775//
[root@centos-01 ~]# ls -l 11.txt //再查看修改 umask前创建文件的权限//
-rw-r--r--. 1 root root 0 12月 23 23:39 11.txt //权限是644//
umask 文件权限 目录权限
022 644 755
002 664 775
如果把umask改成003,那么文件权限要怎么得出呢
666=(rw-rw-rw-)-(-------wx)=rw-rw-r--=664
目录权限
777-003=rwxrwxrwx- -------wx=rwxrwxr--=774
注意:减号减去任何得出的依然是减号
2.17隐藏权限lsattr_chattr
隐藏文件使用 ls -l 命令是看不到的
chattr 设置隐藏权限的命令
#chattr +i 1.txt //给1.txt文件加了一个隐藏权限//
#lsattr 1.txt //查看文件的权限//
[root@centos-01 ~]# lsattr 1.txt
----i----------- 1.txt //多了一个i的权限,不能写,不能重命名,不能删除,touch也不行//
-rw-rw-r--. 1 root root 0 12月 12 23:40 3.txt
drwxr-xr-x. 2 root root 6 12月 12 23:40 anaconda-ks.cfg.1
[root@centos-01 ~]# touch 3.txt
[root@centos-01 ~]# ls -l 3.txt
-rw-rw-r--. 1 root root 0 12月 12 23:40 3.txt //touch 后的文件时间和上面的时间不一样//
去掉 i 权限
#chattr -i 1.txt //给1.txt文件去掉一个隐藏权限//
a权限
#chattr +a 1.txt //只能追加,可以更改时间信息。不能删除,不能更改文件内容,不能重命名//
#chattr -a 1.txt //把这个权限去掉//
目录的权限也一样
#lsattr -R 111 //加R可以查看继承的目录//
#lsattr -a /root/ //可以查看隐藏的文件//
#lsattr -d /root/ //可以目录本身//