设置文件的拥有人和所属组
- 针对一个文件设置权限(切换到root操作)
- 你想理解一个文件的权限,你必须要知道,一个文件的权限和文件的owner和group息息相关。
- 如何修改文件owner和group
- # chown <拥有人> <文件名>
- Topic1
- # chown <拥有人> <文件名>
- # chgrp <所属组> <文件名>
- Topic1
- # chown <拥有人:所属组> <文件名>
- Topic1
- Topic1
- # chown <:所属组> <文件名>
- Topic1
使用chmod命令修改文件权限
- (1)chmod命令参数
- u=user(owner)
- g=group
- o=others
- (2)chmod命令使用
- [root@rhel8 www]# ls -l
- total 0
- -rw-r--r--. 1 root root 0 Mar 6 23:19 women
- [root@rhel8 www]# chmod u=rwx,g=rwx,o=rwx women
- [root@rhel8 www]# ls -l
- total 0
- -rwxrwxrwx. 1 root root 0 Mar 6 23:19 women
- [root@rhel8 www]#
- 表示将拥有人的权限设置为rwx,所属组的权限设置为rwx,其他人的权限设置为rwx
- [root@rhel8 www]# ls -l
- total 0
- -rwxrwxrwx. 1 root root 0 Mar 6 23:19 women
- [root@rhel8 www]# chmod u-x,g-wx,o-rwx women
- [root@rhel8 www]# ls -l
- total 0
- -rw-r-----. 1 root root 0 Mar 6 23:19 women
- [root@rhel8 www]#
- 表示将文件的拥有人减去x权限,问觉得所属组减去wx权限,文件的其他人减去rwx权限
- [root@rhel8 www]# ls -l
- total 0
- -rw-r--r--. 1 root root 0 Mar 6 23:19 women
- [root@rhel8 www]# chmod u+x,g+w,o+w women
- [root@rhel8 www]# ls -l
- total 0
- -rwxrw-rw-. 1 root root 0 Mar 6 23:19 women
- [root@rhel8 www]#
- 表示拥有人加上x权限,所属组加上w权限,其他人加上w权限
- 通过上面的“加权限”,“减权限”,“等于权限”就能设置文件为任何权限
- [root@rhel8 www]# ls -l
Linux的特殊权限详解
- (1)SET UID
- 应用于可执行的普通文件,当一个文件被设置SET UID特殊权限时,任何人一旦执行该文件,都会临时获得文件拥有人的权限。
- [zk@foundation0 dir-test]$ ls -l /bin/passwd -rwsr-xr-x. 1 root root 34512 Aug 13 2018 /bin/passwd
- 在文件拥有者的权限列的执行权限位置,如果该位置是s或S,就表示该文件被设置了SET UID特殊权限
- [root@foundation0 ~]#chmod u-s /bin/passwd [root@foundation0 ~]#ls -l /bin/passwd rwxr-xr-x. 1 root root 34512 Aug 132018 /bin/passwd
- 任何用户都不能修改自己的密码
- (2)SET GID【考试会考】
- 应用于目录文件,当一个目录被设置SET GID特殊权限时,任何用户在该目录下创建文件,文件所属组都会变成被设置SET GID那个目录的所属组
- [zk@foundation0 dir-test]$ chmod g+s zk-dir1 [zk@foundation0 dir-test]$ ls -ld zk-dir1 drwxrwSrw