什么是权限

 系统对用户所能执行的功能的限制     
为什么要有权限

为了保护每个用户的自己的工作环境和隐私

权限跟用户的关系 chmod


属主 u r 可读 4

属组 g w 可写 2

其他人 o x 可执行 1

所有 a - 没有权限 0

-R 递归

文件默认权限644 目录默认权限755

查看文件权限

ls -dl /etc 查看目录的权限

chmod a-x test 清除所有权限

三条结论 -- 权限对目录or文件的意义

权限 文件 目录

r 可以查看文件内容 cat head tail 浏览目录及子目录的列表 ls tree


w 可以新增,修改文件内容 可以新建或者删除,移动目录中的文件的权利


x 可以执行文件的权利 脚本 可以进入目录 cd


1、查看目录下文件的最小权限,目录最小权限是可执行,文件的最小权限是可读

2、修改目录下文件的最小权限,目录最小权限是可执行,文件的最小权限是可读可写

3、执行目录下文件的最小权限,目录最小权限是可执行,文件的最小权限是可执行

[root@2021 ~]# ll
total 8
-rw-r--r-- 1 root root 0 Apr 2 21:14 a.txt
-rw-r--r-- 1 root root 30 Mar 21 02:44 pass.txt
-rw-r--r-- 1 root root 1258 Mar 21 18:51 passwd

rw- r-- r-- 644


只有root是超级权限 其他普通用户只有修改自己的权限

修改权限的三种方法:

chmod u+x,g+x.o+x a.txt 加减法
chmod u=rx,g=x.o=wx a.txt 赋值法
chmod 666 a.txt 数字法

ACL —高级权限

ACL是为了解决某种特殊环境下的,用户权限需求。

- setfacl : 设置acl权限
- getfacl :查看ACL权限

acl权限归属

  • u : 指定用户
  • g : 指定组
  • o : 修改其他用户权限
  • m : 指定mask权限
  • -x: 删除权限
  • -d:继承权限
  • -b:删除全部

注:默认情况下,ACL权限跟普通权限保持一致

## umask

就是解决目录及文件的默认权限。

- 文件的最高权限是多少 666
- 文件夹的最高权限是多少 777

例:
[root@2021 ~]# setfacl -m u:egon:rw a.txt

[root@2021 ~]# getfacl a.txt
# file: a.txt
# owner: root
# group: root
user::rw-
user:egon:rw-
group::r--
mask::rw-
other::r--

设备其他人没有权限

sefacl -m o:- a.txt

继承权限:
setfacl -m d:u:egon:rw a.txt

特殊权限

root@localhost ~]# chattr +a /opt/1.txt # 允许追加内容

[root@localhost ~]# chattr +i /opt/2.txt # 禁⽌任何修改

[root@localhost ~]# chattr +A /opt/3.txt # 不更改⽂件访问时间


umask值存放的地方 默认002 可以修改

cat /etc/bashrc cat /etc/profile


改变属性 chown

[root@2021 ~]# ll
total 8
-rw-rw-r--+ 1 root root 0 Apr 2 21:14 a.txt

[root@2021 ~]# chown egon.egon a.txt
[root@2021 ~]# ll
total 8
-rw-rw-r--+ 1 egon egon 0 Apr 2 21:14 a.txt

SU与SUDO

用于普通用提升权限的。

  • 相关的文件:​​/etc/sudoers​
  • 检查​​/etc/sudoers​​是否修改正确:visudo -c
  • sudoers文件格式
登录shell
全局配置⽂件:
/etc/profile
/etc/profile.d/*.sh
/etc/bashrc
个⼈配置⽂件:
~/.bash_profile
~/.bashrc
登录xshell  ---由高到底      
/etc/profile
/etc/profile.d/*.sh
/etc/bashrc
~/.bash_profile
~/.bashrc
非登录xshell ---由高到底
~/.bashrc
/etc/bashrc
/etc/profile.d/*.sh
[root@2021 ~]# su - egon     --个人登录
Last login: Wed Mar 31 15:10:29 CST 2021 from 10.10.0.1 on pts/1
/etc/profile
yum源终于在凌晨2点30完成了
.bash_profile
.bashrc
/etc/bashrc

环境变量

echo=$PATH

mkdir /2021
vim /2021/mm 编辑内容
chmod +x /2021/mm
PATH=/2021/$PATH
export PATH
source /etc/bashrc 生效 或 重启
必须写决定路径:which查看命令全路径

只支持vim命令提权

xianchen ALL=(ALL) /usr/bin/vim

支持所有的命令提权

tom ALL=(ALL) ALL

不支持某个命令提权

tom ALL=(ALL) ALL, !/usr/bin/vim

不支持某个命令的部分功能
xiaochen ALL=(ALL) ALL, !/usr/bin/vim /opt/mm.xex