文件目录权限
一、常规权限
r 读取 4
w 写入 2
x 执行 1
针对文件:
r 只能查看文件内容
w 修改文件内容
x 针对可执行脚本文件
针对目录:
r 只能查看目录下的文件
w 可以创建,修改该目录文件
x 可切换进该目录
[root@shane ~]# ls -l /etc/fstab //查看文件权限
-rw-r--r--. 1 root root 465 Dec 15 16:40 /etc/fstab
三位一组
第一组:属主用户对文件的操作权限
第二组:属组对文件的操作权限
第三组:其他用户
[root@shane ~]# ls -ld /etc/ //查看目录权限
drwxr-xr-x. 142 root root 8192 Dec 21 17:11 /etc/
二、修改权限的常用命令
1、修改属主、属组
chown 用户名.用户组名 文件名称
[root@shane ~]# chown mysql:mysql /test/1.txt
2、修改属组
chgrp 用户组名 文件名称
[root@shane ~]# chgrp caiwu /test/4.txt
3、修改权限位
chmod a/u/g/o +/-/= rwx 文件名称
u: 属主用户
g: 属组
o: 其他用户
a: 所有
[root@shane ~]# chmod u+x /test/1.txt
[root@shane ~]# chmod g-r,o-r /test/2.txt
[root@shane ~]# chmod a+x /test/3.txt
chmod 777 文件名称
[root@shane ~]# chmod 600 /test/4.txt
[root@shane ~]# chmod 642 /test/5.txt
三、特殊权限
suid 4
sgid 2
sticky bit 1
1、suid
针对可执行文件设置 ,当普通用户运行文件,会临时获取到该文件属主对操作系统的操作权限
[root@shane ~]# chmod u+s /usr/bin/passwd
[root@shane ~]# ls -l /usr/bin/passwd
-rwsr-xr-x. 1 root root 27832 Jun 10 2014 /usr/bin/passwd
2、sgid
针对目录设置,目录拥有sgid权限后,在该目录创建的文件会自动继承目录的属组
[root@shane ~]# chmod g+s /opt/testdir/
[root@shane ~]# ls -ldh /opt/testdir/
drwxr-srwx. 2 root caiwu 32 Dec 21 21:58 /opt/testdir/
3、sticky bit
针对目录设置
防止普通用户互删文件
只有文件属主、目录属主、root用户可删除该目录下的文件
[root@shane ~]# chmod o+t /opt/bj/
[root@shane ~]# ls -ldh /opt/bj/
drwxr-xrwt. 2 root root 6 Dec 21 22:06 /opt/bj/