IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> linux-用户的权限 -> 正文阅读

[系统运维]linux-用户的权限

一、基本权限UGO
1、设置权限的两个方面
2、权限的三种类 对象
  • 属主:u(user)
  • 属组:g(group)
  • 其他人:o(other)
  • 特殊对象:所有人:a(all)(u+g+o)
3、权限的三种 类型(八进制)
  • 读:r=4
  • 写:w=2
  • 执行:x=1
4、 设置权限
4.1使用符号
chmod(change?mode)命令:
可以修改 u g o?的? r-4? ?w-2? x-1
语法:
?chmod? ? ? ? ? ?u+r? ? ? ? ? ? ? ? ?1.txt
? ? 命令? ? ? 对象加减权限? ? ? 文件或目录
注意:这是在对文件授权;在对 文件夹授权时需要 ? -r
[root@localhost ~]# cd???/tmp/
[root@localhost tmp]#
//先进入到(tmp)临时目录中去
[root@localhost tmp]# touch file1
//创建文件file1
[root@localhost tmp]# ls -l
[root@localhost tmp]#?ll file1
- rw-? ?r--? ? r--.? ? ? ? 1? ? ? ?root? ? ? root????????0? ? ? ? ? ? ? ??
?属主?属组?其他人? ?链接? ? ?属主? ? ? 属组? ? ? 大小
7月??27? ??15:14? ? ? file1
? ? ?创建时间? ? ? ? ? 文件名
rwx:表示拥有所有权限
要求1:给file授予属主读的权限,没有写和执行
[root@localhost ~]# chmod u=r file1
[root@localhost ~]# ls -l file1
-r--r--r--. 1 root root 0 7月??27 15:57 file1
要求2:给file授予属组读、写和执行的权限
[root@localhost ~]# chmod g=rwx file1
[root@localhost ~]# ls -l file1
-r--rwxr--. 1 root root 0 7月??27 15:57 file1
要求3:给file授予其他用户没有读写和执行的权限
[root@localhost ~]# chmod o=??file1
[root@localhost ~]# ls -l file1
-r--rwx---. 1 root root 0 7月??27 15:57 file1
[root@localhost tmp]# ls -l -d /tmp/
drwxrwxrwt. 179 root root 16384 7月??27 16:10 /tmp/
用数字修改权限
1:执行 ? ? ?2:写 ? ? ? 4:读
[root@localhost tmp]# chmod 777 /tmp/file1
[root@localhost tmp]# ls -l /tmp/file1
-rwxrwxrwx. 1 root root 0 7月??27 15:14 /tmp/file1
——————————————————————
chown命令(change?owner)
可以修改用户和组
[root@localhost tmp]# chown? user01.hr /tmp/file1
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?用户? ? ?组
[root@localhost tmp]# ls -l /tmp/file1
-rwxrwxrwx. 1 user01 hr 0 7月??27 15:14 /tmp/file1
chogrep:只能修改组
注意:以上三种修改方式均可在文件中适用
但是在文件中的设置权限不会添加到子文件下的文件中
如需添加在命令中加? ? ?-r(递归)
案例:[root@localhost tmp]#??mkdir /temp/hr
mkdir: 无法创建目录"/temp/hr": 没有那个文件或目录
[root@localhost tmp]#??mkdir /tmp/hr
[root@localhost tmp]# ls -d /tmp/hr
/tmp/hr
[root@localhost tmp]# ls -d /tmp/hr -l
d rwx r-x r-x. 2 root root 6 7月??27 17:07 /tmp/hr
//查看修改前
[root@localhost tmp]# chmod 770 /temp/hr
//给r和g全部权限? 给o?没有任何权限
[root@localhost tmp]# ls -l -d???/tmp/hr
//查看修改后
drwxrwx---. 2 root root 6 7月??27 17:07 /tmp/hr
二、ACL文件权限管理
特点:可以设置不同的用户,不同的基本权限(r,w,x)对象数量不同;
UGO:只能一个用户,一个组,或者其他人
语法:setfacl(设置文件访问控制列表)
setfacl? -m? u(user)/g(group)/o(other):hr:rwx /文件路径
? ? ? ? ? ? 设置? ? ? ? ? ? ? ? ? ? ?对象? ? ? :对象名:权限
root@localhost tmp]# touch /home/test
//创建文件
[root@localhost tmp]# ls /home
1??AAA??BBB??test??user01??user02??user03??user04??yps
[root@localhost tmp]# ls -l /home/test
-rw-r--r--. 1 root root 0 7月??27 20:17 /home/test
//查看文件
1、查看文件权限
[root@localhost tmp]# getfacl /home/test
getfacl: Removing leading '/' from absolute path names
# file: home/test
# owner: root
# group: root
user::rw-
group::r--
other::r--
2、设置用户权限
注意:设置之前一定要先创建用户
[root@localhost tmp]# useradd user01
[root@localhost tmp]# useradd user02
_________________________________________________
[root@localhost tmp]# setfacl??-m u:user01: rw /home/test
[root@localhost tmp]# setfacl??-m u:user02: - /home/test
[root@localhost tmp]# getfacl??/home/test
getfacl: Removing leading '/' from absolute path names
# file: home/test
# owner: root
# group: root
user::rw-
user:user01:rw-
user:user02:---
group::r--
mask::rw-
other::r--
3.删除
[root@localhost tmp]# setfacl -x u:user01 /home/test
//删除用户访问权限(注意:不用写权限(r,w,x))
[root@localhost tmp]# getfacl /home/test
getfacl: Removing leading '/' from absolute path names
# file: home/test
# owner: root
# group: root
user::rw-
user:user02:---
group::r--
mask::r--
other::r--
建立:-m? ?;删除:-x? ;清除干净:-b? ?;
三、特殊权限(了解)
例如:不小心删除了文件怎么办
1、特殊位 suid
功能:使调用文件的用户,临时具备属主能力
[root@localhost ~]# chmod u+s(suid) /home/test
[root@localhost ~]# ls??-l??/home/test
-rwsrw----+ 1 user01 hr 0 7月??27 20:17 /home/test
2、文件属性 chattr? ? -i(不可以被删除)
wghtsch - n1‘?getfacl /tmp/file1
wghtsch - n1‘ lsattr /tmp/file1
3、进程掩码 umask :掩码与权限相反
掩码0022+权限0755=0777
文件的默认权限为644:
目的:系统为例保护自己,在新建的文件上取消了执行权限
[root@localhost ~]# umask
0022
[root@localhost ~]# mkdir yangpanshaui
[root@localhost ~]# touch yangpanshauifile
[root@localhost ~]# ls -dl yangpanshaui??yangpanshauifile
drwxr-xr-x. 2 root root 6 7月??28 11:11 yangpanshaui
-rw-r--r--. 1 root root 0 7月??28 11:11 yangpanshauifile
  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2022-08-06 11:16:52  更:2022-08-06 11:19:37 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/18 21:39:24-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码