RHCSA_DAY08
locate与find查找
locate:/var/lib/mlocate/mlocate.db
getfacl 目录
chmod权限管理
chmod(英文全拼:change mode)设置用户对文件的权限
命令格式:chmod [-选项] 归属关系+-=权限类别 文件...
root用户可以修改任何文件和目录的权限
文件所有者
常用选项:
-R 递归修改,包含目录下所有的子文件与子目录
归属关系:u 所有者 g 所属组 o 其他人
权限类别: r 读取 w 写入 x 执行 - 没有权限
操作:+ 添加权限 - 去除权限 = 重新定义权限
权限数字表示:r ---- 4 w ---- 2 x ---- 1 0 没有权限
#查看文件详细属性
[root@localhost ~]# ll hello
-rw-r--r--. 1 root root 426 3月 28 15:00 hello
#为文件所有者添加执行权限
[root@localhost ~]# chmod u+x hello
[root@localhost ~]# ll hello
-rwxr--r--. 1 root root 426 3月 28 15:00 hello
#为文件所属组添加写权限
[root@localhost ~]# chmod g+w hello
[root@localhost ~]# ll hello
-rwxrw-r--. 1 root root 426 3月 28 15:00 hello
#为文件其他人添加写权限
[root@localhost ~]# chmod o+w hello
[root@localhost ~]# ll hello
-rwxrw-rw-. 1 root root 426 3月 28 15:00 hello
#使用(逗号)可以同时为多个用户授权
[root@localhost ~]# chmod g+x,o+x hello
[root@localhost ~]# ll hello
-rwxrwxrwx. 1 root root 426 3月 28 15:00 hello
#去除所有者执行权限
[root@localhost ~]# chmod u-x hello
[root@localhost ~]# ll hello
-rw-rwxrwx. 1 root root 426 3月 28 15:00 hello
#去除所属组执行权限
[root@localhost ~]# chmod g-x hello
[root@localhost ~]# ll hello
-rw-rw-rwx. 1 root root 426 3月 28 15:00 hello
#去除其他人执行权限
[root@localhost ~]# chmod o-x hello
[root@localhost ~]# ll hello
-rw-rw-rw-. 1 root root 426 3月 28 15:00 hello
#同时去除ugo写权限
[root@localhost ~]# chmod u-w,g-w,o-w hello
[root@localhost ~]# ll hello
-r--r--r--. 1 root root 426 3月 28 15:00 hello
#重新定义所有者权限
[root@localhost ~]# chmod u=rwx hello
[root@localhost ~]# ll hello
-rwxr--r--. 1 root root 426 3月 28 15:00 hello
#重新定义所属组权限
[root@localhost ~]# chmod g=rwx hello
[root@localhost ~]# ll hello
-rwxrwxr--. 1 root root 426 3月 28 15:00 hello
#重新定义其他人权限
[root@localhost ~]# chmod o=rwx hello
[root@localhost ~]# ll hello
-rwxrwxrwx. 1 root root 426 3月 28 15:00 hello
#创建目录并设置目录权限
[root@localhost ~]# mkdir /test
[root@localhost ~]# ll -d /test
drwxr-xr-x. 2 root root 6 4月 11 14:30 /test
#为目录所属组添加写权限
[root@localhost ~]# chmod g+w /test
[root@localhost ~]# ll -d /test
drwxrwxr-x. 2 root root 6 4月 11 14:30 /test
#为目录其他人添加写权限
[root@localhost ~]# chmod o+w /test
[root@localhost ~]# ll -d /test
drwxrwxrwx. 2 root root 6 4月 11 14:30 /test
[root@localhost ~]#
#重新定义所有用户权限
[root@localhost ~]# chmod u=rwx,g=rx,o=rx /test
[root@localhost ~]# ll -d /test
drwxr-xr-x. 2 root root 6 4月 11 14:30 /test
#同时为所有用户定义相同权限
[root@localhost ~]# chmod ugo=rwx /test
[root@localhost ~]# ll -d /test
drwxrwxrwx. 2 root root 21 4月 11 14:37 /test
#权限数字定义方式
[root@localhost ~]# ll hello
-rwxrwxrwx. 1 root root 426 3月 28 15:00 hello
所有者:rwx 4+2+1=7
所属组:r 4
其他人:r 4
[root@localhost ~]# chmod 744 hello
[root@localhost ~]# ll hello
-rwxr--r--. 1 root root 426 3月 28 15:00 hello
所有者:rw 4+2=6
所属组:rw 4+2=6
其他人:--- 0
[root@localhost ~]# chmod 660 hello
[root@localhost ~]# ll hello
-rw-rw----. 1 root root 426 3月 28 15:00 hello
所有者:rwx 4+2+1=7
所属组:wx 2+1=3
其他人:--- 0
[root@localhost ~]# touch /hello.txt
[root@localhost ~]# ll /hello.txt
-rw-r--r--. 1 root root 0 4月 11 14:45 /hello.txt
[root@localhost ~]# chmod 730 /hello.txt
[root@localhost ~]# ll /hello.txt
-rwx-wx---. 1 root root 0 4月 11 14:45 /hello.txt
#去除所有用户权限
[root@localhost ~]# chmod 000 /hello.txt
[root@localhost ~]# ll /hello.txt
----------. 1 root student 0 4月 11 14:45 /hello.txt
#递归修改目录下所有子文件与子目录权限
[root@localhost ~]# ll -d /test
drwxrwxrwx. 2 root root 21 4月 11 14:37 /test
[root@localhost ~]# mkdir /test/xxoo
[root@localhost ~]# ll -d /test/xxoo/
drwxr-xr-x. 2 root root 6 4月 11 14:54 /test/xxoo/
[root@localhost ~]# ll /test/abc.txt
-rw-r--r--. 1 root root 0 4月 11 14:37 /test/abc.txt
#默认用户在该目录下创建文件权限与父目录不一致
#递归修改目录下所有子文件与子目录权限
[root@localhost ~]# chmod -R 777 /test
[root@localhost ~]# ll /test/abc.txt
-rwxrwxrwx. 1 root root 0 4月 11 14:37 /test/abc.txt
[root@localhost ~]# ll -d /test/xxoo
drwxrwxrwx. 2 root root 6 4月 11 14:54 /test/xxoo
#深入理解权限,
[root@localhost ~]# mkdir /test1
[root@localhost ~]# chmod 777 /test1
[root@localhost ~]# ll -d /test1
drwxrwxrwx. 2 root root 6 4月 11 14:57 /test1
#在该目录下创建文件与目录
[root@localhost ~]# touch /test1/root.txt
[root@localhost ~]# mkdir /test1/rootbak
[root@localhost ~]# chmod o=rx /test1
[root@localhost ~]# ll -d /test1
drwxrwxr-x. 2 root root 6 4月 11 14:59 /test1
[root@localhost ~]# touch /test1/root.txt
#普通用户对该目录如果拥有rwx权限是可以删除该目录下任何用户创建的文件(包括root)
[user1@localhost ~]$ cd /test1
[user1@localhost test1]$ ls
root.txt
[user1@localhost test1]$ ll root.txt
-rw-r--r--. 1 root root 0 4月 11 14:57 root.txt
[user1@localhost test1]$ rm -rf root.txt
[user1@localhost test1]$ ls
rootbak
[user1@localhost test1]$ rm -rf rootbak/
[user1@localhost test1]$ ls
[user1@localhost test1]$ ll -d /test1
drwxrwxrwx. 2 root root 6 4月 11 14:59 /test1
总结:
1.用户对文件拥有写权限可以增加/修改/删除文件里内容,并不能删除文件,删除文件取决于对文件的父目录有没有rwx权限
2.用户对目录拥有rwx权限可以查看/创建/修改/删除目录下的文件
umask预设权限
- umask用于显示或设置创建文件的权限掩码
- 命令格式:umask [-p] [-S] [mode]
root@localhost ~]# mkdir /test2
[root@localhost ~]# ll -d /test2
drwxr-xr-x. 2 root root 6 4月 11 15:05 /test2
[root@localhost ~]# umask --help
umask: 用法:umask [-p] [-S] [模式]
#查看目录默认权限掩码,以数字形式显示
[root@localhost ~]# umask -p
umask 0022
#查看目录默认权限掩码,以字母形式显示
[root@localhost ~]# umask -S
u=rwx,g=rx,o=rx
#设置目录默认权限掩码,为所属组添加写权限
[root@localhost ~]# umask g+w
[root@localhost ~]# mkdir /test3
[root@localhost ~]# ll -d /test3
drwxrwxr-x. 2 root root 6 4月 11 15:09 /test3
#去除目录默认权限掩码
[root@localhost ~]# umask g-w
[root@localhost ~]# mkdir /test4
[root@localhost ~]# ll -d /test4
drwxr-xr-x. 2 root root 6 4月 11 15:10 /test4
chown归属关系管理
chown(英文全拼:change owner)用于设置文件的所有者和所属组关系
命令格式:
chown [-选项] 所有者:所属组 文档 #同时修改所有者和所属组身份
chown [-选项] 所有者 文档 #只修改所有者身份
chown [-选项] :所属组 文档 #只修改所属组身份
常用选项:
-R 递归修改
#创建文件
[root@localhost ~]# chmod 744 /hello.txt
[root@localhost ~]# ll /hello.txt
-rwxr--r--. 1 root student 0 4月 11 14:45 /hello.txt
#修改文件所有者为user1用户
[root@localhost ~]# chown user1 /hello.txt
[root@localhost ~]# ll /hello.txt
-rwxr--r--. 1 user1 student 0 4月 11 14:45 /hello.txt
#修改文件所有者与所属组为lisi
[root@localhost ~]# chown lisi:lisi /hello.txt
[root@localhost ~]# ll /hello.txt
-rwxr--r--. 1 lisi lisi 4 4月 11 15:26 /hello.txt
#创建目录
[root@localhost ~]# mkdir /test5
[root@localhost ~]# ll -d /test5
drwxr-xr-x. 2 root root 6 4月 11 15:30 /test5
#修改目录所有者与所属组为lisi
[root@localhost ~]# chown lisi:lisi /test5
[root@localhost ~]# ll -d /test5
drwxr-xr-x. 2 lisi lisi 6 4月 11 15:30 /test5
[root@localhost ~]# touch /test5/root.txt
[root@localhost ~]# ll /test5/root.txt
-rw-r--r--. 1 root root 0 4月 11 15:31 /test5/root.txt
#递归修目录下所有子文件与子目录归属关系
[root@localhost ~]# chown -R lisi:lisi /test5
[root@localhost ~]# ll /test5/root.txt
-rw-r--r--. 1 lisi lisi 0 4月 11 15:31 /test5/root.txt
SetUID特殊权限
SetUID(SUID):对于一个可执行的文件用了SUID权限后,普通用户在执行该文件后,临时拥有文件所有者的身份,该权限只在程序执行过程中有效,程序执行完毕后用户恢复原有身份
SetUID权限会附加在所有者的 x 权限位上,所有者的 x 权限标识会变成 s
设置SetUID命令格式:chmod u+s 文件名
#搜索命令绝对路径
[root@localhost ~]# which passwd
/usr/bin/passwd
[root@localhost ~]# ll /usr/bin/passwd
-rwsr-xr-x. 1 root root 27832 6月 10 2014 /usr/bin/passwd
[root@localhost ~]# which cat
/usr/bin/cat
[root@localhost ~]# ll /usr/bin/cat
-rwxr-xr-x. 1 root root 54160 10月 31 2018 /usr/bin/cat
#普通用户使用cat命令是默认无法查看/etc/shadow文件内容
[lisi@localhost ~]$ cat /etc/shadow
cat: /etc/shadow: 权限不够
#设置SUID权限
[root@localhost ~]# chmod u+s /usr/bin/cat
[root@localhost ~]# ll /usr/bin/cat
-rwsr-xr-x. 1 root root 54160 10月 31 2018 /usr/bin/cat
#普通用户再次使用cat命令时临时获取文件所有者身份
[lisi@localhost ~]$ cat /etc/shadow
#去除SUID权限
[root@localhost ~]# chmod u-s /usr/bin/cat
[root@localhost ~]# ll /usr/bin/cat
-rwxr-xr-x. 1 root root 54160 10月 31 2018 /usr/bin/cat
[root@localhost ~]# which vim
/usr/bin/vim
[root@localhost ~]# ll /usr/bin/vim
-rwxr-xr-x. 1 root root 2294208 10月 31 2018 /usr/bin/vim
#为vim设置SUID权限
[root@localhost ~]# chmod u+s /usr/bin/vim
[root@localhost ~]# ll /usr/bin/vim
-rwsr-xr-x. 1 root root 2294208 10月 31 2018 /usr/bin/vim
[root@localhost ~]# ll /etc/passwd
-rw-r--r--. 1 root root 2737 4月 10 17:26 /etc/passwd
[root@localhost ~]# chmod u-s /usr/bin/vim
[root@localhost ~]# vim /etc/passwd
SetGID特殊权限
SetGID(SGID):当对一个可执行的二进制文件设置了SGID后,普通用户在执行该文件时临时拥有其所属组的权限,该权限只在程序执行过程中有效,程序执行完毕后用户恢复原有组身份
当对一个目录作设置了SGID权限后,普通用户在该目录下创建的文件的所属组,均与该目录的所属组相同
SetGID权限会附加在所属组的 x 权限位上,所属组的 x 权限标识会变成 s
设置SetGID命令格式:chmod g+s 文件名
[root@localhost ~]# mkdir /test6
[root@localhost ~]# chmod 777 /test6
[root@localhost ~]# ll -d /test6
drwxrwxrwx. 2 root root 6 4月 11 15:59 /test6
#为目录设置SGID权限
[root@localhost ~]# chmod g+s /test6
[root@localhost ~]# ll -d /test6
drwxrwsrwx. 2 root root 6 4月 11 15:59 /test6
#SGID权限会附加在所属组执行权限位,所属组执行权限变为s
[root@localhost ~]# touch /test6/1.txt
[root@localhost ~]# ll /test6/1.txt
-rw-r--r--. 1 root root 0 4月 11 16:00 /test6/1.txt
#修改目录所属组为lisi组
[root@localhost ~]# chown :lisi /test6
[root@localhost ~]# ll -d /test6
drwxrwsrwx. 2 root lisi 19 4月 11 16:00 /test6
#SGID对目录设置后,在该目录下创建的任何文件都会继承父目录的所属组
[root@localhost ~]# touch /test6/2.txt
[root@localhost ~]# ll /test6/2.txt
-rw-r--r--. 1 root lisi 0 4月 11 16:01 /test6/2.txt
Sticky BIT特殊权限
Sticky BIT(SBIT):该权限只针对于目录有效,当普通用户对一个目录拥有w和x权限时,普通用户可以在此目录下拥有增删改的权限,应为普通用户对目录拥有w权限时,是可以删除此目录下的所有文件
如果对一个目录设置了SBIT权限,除了root可以删除所有文件以外,普通用户就算对该目录拥有w权限,也只能删除自己建立的文件,不能删除其他用户建立的文件
SBIT权限会附加在其他人的 x 权限位上,其他人的 x 权限标识会变成 t
设置SBIT命令格式:chmod o+t 目录名
#为目录设置SBIT
[root@localhost ~]# chmod o+t /test
[root@localhost ~]# ll -d /test
drwxrwxrwt. 2 root root 6 4月 11 16:07 /test
[lisi@localhost test]$ ls
kenji.txt laowang.txt lisi.txt
[lisi@localhost test]$ rm -rf *
rm: 无法删除"kenji.txt": 不允许的操作
rm: 无法删除"laowang.txt": 不允许的操作
FACL访问控制列表
FACL(Filesystemctl Access Control List)文件系统访问控制列表:利用文件扩展属性保存额外的访问控制权限,单独为每一个用户量身定制一个权限
命令格式:setfacl 选项 归属关系:权限 文档
常用选项:
-m 设置权限
-x 删除指定用户权限
-b 删除所有用户权限
#为natasha用户设置ACL权限
[root@localhost ~]# setfacl -m u:natasha:rx /yunwei/
[root@localhost ~]# ll -d /yunwei/
drwxrwx---+ 2 root yunwei 54 4月 11 16:43 /yunwei/
[root@localhost ~]# ll -d /test
drwxrwxrwt. 2 root root 42 4月 11 16:11 /test
#查看目录ACL权限
[root@localhost ~]# getfacl /yunwei
getfacl: Removing leading '/' from absolute path names
# file: yunwei
# owner: root
# group: yunwei
user::rwx
user:natasha:r-x
group::rwx
mask::rwx
other::---
#用户测试权限
[natasha@localhost ~]$ ls /yunwei/
hell.sh kenji.txt lisi.txt
[natasha@localhost yunwei]$ rm -rf kenji.txt
rm: 无法删除"kenji.txt": 权限不够
[natasha@localhost yunwei]$ touch natasha.txt
touch: 无法创建"natasha.txt": 权限不够
[natasha@localhost yunwei]$ vim kenji.txt
[root@localhost ~]# setfacl -m u:tom:rx /yunwei
[root@localhost ~]# setfacl -m u:jack:rx /yunwei
[root@localhost ~]# setfacl -m u:hary:rx /yunwei
[root@localhost ~]# getfacl /yunwei
getfacl: Removing leading '/' from absolute path names
# file: yunwei
# owner: root
# group: yunwei
user::rwx
user:hary:r-x
user:tom:r-x
user:natasha:r-x
user:jack:r-x
group::rwx
mask::rwx
other::---
#删除指定用户ACL权限
[root@localhost ~]# setfacl -x u:tom /yunwei
[root@localhost ~]# getfacl /yunwei
getfacl: Removing leading '/' from absolute path names
# file: yunwei
# owner: root
# group: yunwei
user::rwx
user:hary:r-x
user:natasha:r-x
user:jack:r-x
group::rwx
mask::rwx
other::---
#删除所有用户ACL权限
[root@localhost ~]# setfacl -b /yunwei
[root@localhost ~]# getfacl /yunwei
getfacl: Removing leading '/' from absolute path names
# file: yunwei
# owner: root
# group: yunwei
user::rwx
group::rwx
other::---
RHCSA_DAY08的更多相关文章
随机推荐
- 关于.Net Core使用Elasticsearch(俗称ES)、Kibana的研究说明
关于ElasticSearch Elasticsearch是一个分布式的开源搜索和分析引擎,适用于所有类型的数据,包括文本.数字.地理空间.结构化和非结构化数据.Elasticsearch 在 Apa ...
- BFS经典面试题——C++版
文章目录 蛇梯棋 单词接龙 青蛙过河 蛇梯棋 N x N 的棋盘 board 上,按从 1 到 N*N 的数字给方格编号,编号 从左下角开始,每一行交替方向. 例如,一块 6 x 6 大小的棋盘,编号 ...
- 28、windows下通过MSI图形界面方式安装mysql
28.1.下载mysql: 1. www.mysql.com 2. 3. https://dev.mysql.com/downloads/mysql/ 4. 5. 28.2.安装: 双击下载的&quo ...
- Destroying The Graph 最小点权集--最小割--最大流
Destroying The Graph 构图思路: 1.将所有顶点v拆成两个点, v1,v2 2.源点S与v1连边,容量为 W- 3.v2与汇点连边,容量为 W+ 4.对图中原边( a, b ), ...
- 重新整理 .net core 实践篇————重定向攻击[三十九]
前言 简单介绍一下重定向攻击. 正文 攻击思路: 看着上面挺复杂的,其实是一些很简单的步骤. 攻击者通过某些手段,让用户打开了一个好站点,打开的这个地址里面带有重定向信息,重定向信息就是自己伪造的站点 ...
- 使用RSA和DES保护的Socket通信
基本要求:将DES加密算法应用于网络通信,使用RSA算法自动分配密钥,设计好界面,可验证自动生成的密钥和加解密正确的结果. 具体实现要求:客户端和服务器建立连接后,客户端生成一个随机DES密钥;服务器 ...
- Docker:部署PXC8.0集群时,启动容器报错New joining cluster node didn‘t find all needed SSL artifacts
使用docker部署mysql PXC集群8.0版本,启动第二个节点的时候遇到报错,New joining cluster node didn't find all needed SSL artifa ...
- linux安装subversion
原文: https://www.cnblogs.com/liuxianan/p/linux_install_svn_server.html 安装 使用yum安装非常简单: yum install su ...
- 各种电子书、pdf
剑指offer第二版: 链接:https://pan.baidu.com/s/1ABn3p9wY_kiQUzDRefZUqA 提取码:d30v 网络是怎样连接的: 链接:https://pan. ...
- cobbler安装4个报错汇总及解决方法:ImportError
安装完,检查cobbler:cobbler check发现这个问题ImportError: No module named yaml 具体报错如下: [root@www localdisk]# cob ...