麒麟操作系统基础知识保姆级教程(十五)权限管理

如果你想拥有你从未拥有过的东西,那么你必须去做你从未做过的事情

之前咱们了解过了麒麟操作系统的sudo提权,那么都有哪些关于咱们权限有哪些相关的知识呢?

💬欢迎交流:在学习过程中如果你有任何疑问或想法,欢迎在评论区留言,我们可以共同探讨学习的内容。你的支持是我持续创作的动力!

👍点赞、收藏与推荐:如果你觉得这篇文章对你有所帮助,请不要忘记点赞、收藏,并分享给更多的小伙伴!你们的鼓励是我不断进步的源泉!

🚀推广给更多人:如果你认为这篇文章对你有帮助,欢迎分享给更多对Linux感兴趣的朋友,让我们一起进步,共同提升!

目录

一、麒麟操作系统权限认识

1、用户类型及权限

2、用户和组的管理

3、权限分配与限制机制

4、权限提升方法

5、共享文件权限配置

二、权限管理

1、rwx含义

2、修改文件权限

3、对于文件rwx的含义

4、rwx对于目录的作用

5、Linux系统默认权限

6、隐藏权限

小屁吐槽

小结

一、麒麟操作系统权限认识

1、用户类型及权限

1、超级管理员(root):在麒麟操作系统中,root 用户的用户标识号(uid)为 0,对所有的命令和文件具有完全的访问、修改、执行权限,可进行系统的任何操作,但操作失误容易对系统造成损坏,因此使用时需谨慎 。
​
    2、普通用户:由管理员创建,权限受到一定限制,一般只在自己的主目录拥有完全权限。若要执行需要管理员权限的命令,可使用sudo命令提升权限。
​
    3、系统用户:通常用于守护进程或软件,安装系统后默认存在,默认情况下不允许通过 shell 的交互式登录系统,但对系统的正常运行不可或缺.
​
    4、虚拟用户:如 nobody 和 ftp 等,用于完成特定任务,没有登录系统的权限,但可以进行其他特定操作。

2、用户和组的管理

1、用户管理:通过useradd命令创建用户,使用passwd命令修改用户密码,usermod命令修2、改用户属性,userdel命令删除用户。
3、用户组管理:使用groupadd命令创建用户组,usermod -a -G命令将用户添加到指定的用户组。

3、权限分配与限制机制

文件系统访问控制列表(ACL):用于分配和限制用户对文件或目录的访问权限,包含了对文件属主、用户组以及其他用户的权限控制,可通过chmod命令设置文件权限,setfacl命令为目录设置默认权限。
自主访问控制(DAC):传统的 Linux 访问控制方式,一个软件或守护进程以 User ID(UID)或 Set owner User ID(SUID)的身份运行,并拥有该用户对目标的权限。
强制访问控制(MAC):基于保密性和完整性强制信息的隔离以限制破坏,如 AppArmor 和 SELinux 等安全机制。
AppArmor:允许系统管理员将每个程序与一个安全配置文件关联,限制程序的功能,有 enforcement、complain/learning 两种工作模式。
SELinux:主要由美国国家安全局开发,当主体尝试访问目标时,SELinux 安全服务器会根据策略数据库进行检查并授予或拒绝权限,有 Enforcing、Permissive、Disabled 三种模式。
KYSEC:基于 kysec 安全标记对执行程序、脚本文件、共享库、内核模块进行保护,外来的此类文件需添加到麒麟安全管理工具的白名单列表中才能执行调用。

4、权限提升方法

在银河麒麟高级服务器操作系统 V10 中,可将普通用户加入到wheel组来提升其操作权限,使其能够使用sudo命令执行需要管理员权限的命令。

5、共享文件权限配置

创建共享文件夹,并通过编辑 Samba 配置文件/etc/samba/smb.conf,可指定共享文件夹的路径、是否允许浏览、是否允许写入以及允许访问的用户或用户组等共享权限。
同时,需考虑文件系统的安全权限,使用chmod、chown等命令设置文件或目录的权限和所有权,遵循最小权限原则,保障文件的安全性。

二、权限管理

Linux如何知道我对某个文件或目录有什么权限
yunzhongzi02@db01 tmp]$ ll 2.txt 
-rw-r--r-- 1 root root 0 Mar 14 10:30 2.txt
[yunzhongzi02@db01 tmp]$ #如何知道我对2.txt拥有什么权限
[yunzhongzi02@db01 tmp]$ #1.当前登录用户 yunzhongzi02
[yunzhongzi02@db01 tmp]$ #2.yunzhongzi02和2.txt的关系
[yunzhongzi02@db01 tmp]$ #关系1.属主 2.属组 3.其他陌生人
[yunzhongzi02@db01 tmp]$ #3.通过关系找到自己的权限位置
[yunzhongzi02@db01 tmp]$ #前3位 属主 中三位 属组  后三位: 其他陌生人

1、rwx含义

r   可读,可查看 cat less vim
w   可读,可写   vim echo > >>
x   可执行 sh test.sh 文件中必须是可执行的命令
r ==== 4
w ==== 2
x ==== 1
通过数字的方式表示文件的权限:
rw-r--r-- 通过数字方式表现为:将每3位的权限位置换算成数字进行相加等于644
rw-     属主-->数字  420  +=6
r--     属组-->数字  400  +=4
r--     其他-->数字  400  +=4
[yunzhongzi@yunzhongziedu tmp]$ ll 1.txt
-rw-r--r-- 1 root root 0 Mar 22 15:28 1.txt #644
通过数字来使用rwx来表示:755
rwxr-xr-x
通过数字来使用rwx来表示:600
rw-------

2、修改文件权限

01.使用rwx修改文件的权限
语法结构:       chmod +x file
使用ugo的方式授权不同的权限位置:
u   表示属主位   user
g   表示属组位   group
o   表示其他位置  other
案例1.授权属主位增加x权限
[root@yunzhongziedu ~]# ll 1.txt
-rw-r--r-- 1 root root 43 Mar 21 20:49 1.txt
[root@yunzhongziedu ~]# chmod u+x 1.txt
[root@yunzhongziedu ~]# ll 1.txt
-rwxr--r-- 1 root root 43 Mar 21 20:49 1.txt
案例2.将属主位的w权限去掉
[root@yunzhongziedu ~]# chmod u-w 1.txt
[root@yunzhongziedu ~]# ll 1.txt
-r-xr--r-- 1 root root 43 Mar 21 20:49 1.txt
案例3.授权属组位wx权限
[root@yunzhongziedu ~]# chmod g+wx 1.txt
[root@yunzhongziedu ~]# ll 1.txt
-r-xrwxr-- 1 root root 43 Mar 21 20:49 1.txt
案例4.取消属组的所有权限
[root@yunzhongziedu ~]# chmod g-rwx 1.txt
[root@yunzhongziedu ~]# ll 1.txt
-r-x---r-- 1 root root 43 Mar 21 20:49 1.txt
案例5.授权属组和其他位置同时增加x权限
[root@yunzhongziedu ~]# chmod go+x 1.txt
[root@yunzhongziedu ~]# ll 1.txt
-r-x--xr-x 1 root root 43 Mar 21 20:49 1.txt
案例6.授权所有位置减少x权限
[root@yunzhongziedu ~]# chmod ugo-x 1.txt
[root@yunzhongziedu ~]# ll 1.txt
-r-----r-- 1 root root 43 Mar 21 20:49 1.txt
案例7.不添加位置添加权限(w只给属主加全部,rx可以加全部)
[root@yunzhongziedu ~]# chmod +w 1.txt
[root@yunzhongziedu ~]# ll 1.txt
-rw----r-- 1 root root 43 Mar 21 20:49 1.txt
[root@yunzhongziedu ~]# chmod +rwx 1.txt
[root@yunzhongziedu ~]# ll 1.txt
-rwxr-xr-x 1 root root 43 Mar 21 20:49 1.txt
案例8.a表示所有位置
[root@yunzhongziedu ~]# chmod -rwx 1.txt
[root@yunzhongziedu ~]# ll 1.txt
---------- 1 root root 43 Mar 21 20:49 1.txt
[root@yunzhongziedu ~]# chmod a+r 1.txt
[root@yunzhongziedu ~]# ll 1.txt
-r--r--r-- 1 root root 43 Mar 21 20:49 1.txt
[root@yunzhongziedu ~]# chmod a+x 1.txt
[root@yunzhongziedu ~]# ll 1.txt
-r-xr-xr-x 1 root root 43 Mar 21 20:49 1.txt
[root@yunzhongziedu ~]# chmod a+w 1.txt
[root@yunzhongziedu ~]# ll 1.txt
-rwxrwxrwx 1 root root 43 Mar 21 20:49 1.txt
案例9.等号表示重新加权限,先清空后加权限
[root@yunzhongziedu ~]# ll 1.txt
-rwxrwxrwx 1 root root 43 Mar 21 20:49 1.txt
[root@yunzhongziedu ~]# chmod u=x 1.txt
[root@yunzhongziedu ~]# ll 1.txt
---xrwxrwx 1 root root 43 Mar 21 20:49 1.txt
    授权所有位置只加rx权限
    [root@yunzhongziedu ~]# chmod ugo=rx 1.txt
    [root@yunzhongziedu ~]# ll 1.txt
    -r-xr-xr-x 1 root root 43 Mar 21 20:49 1.txt
    默认表示所有
    [root@yunzhongziedu ~]# chmod =rwx 1.txt
    [root@yunzhongziedu ~]# ll 1.txt
    -rwxr-xr-x 1 root root 43 Mar 21 20:49 1.txt
02.使用数字的方式修改权限
语法:     chmod +数字 +file
644 -----> rw-r--r--
 r === 4
 w === 2
 x === 1
案例:授权文件权限为:rwxr--r--
[root@yunzhongziedu ~]# chmod 744 1.txt
[root@yunzhongziedu ~]# ll 1.txt
-rwxr--r-- 1 root root 43 Mar 21 20:49 1.txt
案例:修改文件权限为:rw-------
[root@yunzhongziedu ~]# chmod 600 1.txt
[root@yunzhongziedu ~]# ll 1.txt
-rw------- 1 root root 43 Mar 21 20:49 1.txt
案例:授权文件权限为:rwxr-xr-x
[root@yunzhongziedu ~]# chmod 755 1.txt
[root@yunzhongziedu ~]# ll 1.txt
-rwxr-xr-x 1 root root 43 Mar 21 20:49 1.txt
案例:授权文件权限为rwxrwxrwx
[root@yunzhongziedu ~]# chmod 777 1.txt
[root@yunzhongziedu ~]# ll 1.txt
-rwxrwxrwx 1 root root 43 Mar 21 20:49 1.txt

3、对于文件rwx的含义

1.构建环境
[root@yunzhongziedu ~]# mkdir ./yunzhongzi/
[root@yunzhongziedu ~]# touch ./yunzhongzi/{1..3}.txt
[root@yunzhongziedu ~]# echo pwd > ./yunzhongzi/1.txt 
[root@yunzhongziedu ~]# ll ./yunzhongzi
total 4
-rw-r--r-- 1 root root 4 Mar 22 16:04 1.txt
-rw-r--r-- 1 root root 0 Mar 22 16:03 2.txt
-rw-r--r-- 1 root root 0 Mar 22 16:03 3.txt
[root@yunzhongziedu ~]# cat yunzhongzi/1.txt
pwd
2.打开两个窗口
第一个窗口:root用户 修改权限
第二个窗口:su到yunzhongzi进行权限测试
一.测试r对应文件的权限
结果:r对于文件只有读的权限
    写入需要强制 :wq!
[root@yunzhongziedu yunzhongzi]#  chmod u=r 1.txt
[root@yunzhongziedu yunzhongzi]# ll 1.txt
-r--r--r-- 1 yunzhongzi yunzhongzi 4 Mar 22 16:04 1.txt
​
[yunzhongzi@yunzhongziedu ~]$ cat /yunzhongzi/1.txt
pwd
vim写入:-- INSERT -- W10: Warning: Changing a readonly file   wq!强制退出
[yunzhongzi@yunzhongziedu ~]$ cat /yunzhongzi/1.txt
pwd
qy
测试w对于文件的权限
结果:不可以查看文件内容
    只能用> >>输入写入
    不可以执行
[root@yunzhongziedu ~]#  chmod go=r 1.txt
[root@yunzhongziedu ~]# ll 1.txt
--w-r--r-- 1 root root 43 Mar 21 20:49 1.txt
[yunzhongzi@yunzhongziedu ~]$ vim 1.txt
sxadsdadasdawdaxczcasd   #(写入不进去)
[root@yunzhongziedu ~]# cat /yunzhongzi/1.txt
pwd
qy
测试x对于文件的权限
结果:不能看不能写不能执行
[root@yunzhongziedu ~]# chmod u=x /yunzhongzi/1.txt
[root@yunzhongziedu ~]# ll /yunzhongzi/1.txt
---xr--r-- 1 yunzhongzi yunzhongzi 7 Mar 22 16:14 /yunzhongzi/1.txt
总结:文件权限控制文件的可读,可写,可执行
要查看文件必须有:r  权限
要读写文件必须有:rw 权限
执行的文件必须有:rx 权限
普通文件最高权限:666
企业中所有普通文件权限最高必须为:644

4、rwx对于目录的作用

1.r权限对目录的作用:
[root@yunzhongziedu ~]#  chown yunzhongzi.yunzhongzi /yunzhongzi/
[root@yunzhongziedu ~]# ll -d /yunzhongzi/
drwxr-xr-x 2 yunzhongzi yunzhongzi 45 Mar 22 16:03 /yunzhongzi/
[root@yunzhongziedu ~]# chmod u=r /yunzhongzi
[root@yunzhongziedu ~]#  ll -d /yunzhongzi
dr--r-xr-x 2 yunzhongzi yunzhongzi 45 Mar 22 16:03 /oldbo
总结:啥也干不了
2.w权限对目录的作用:
[root@yunzhongziedu ~]#  chmod u=w /yunzhongzi
[root@yunzhongziedu ~]#  ll -d /yunzhongzi
d-w-r-xr-x 2 yunzhongzi yunzhongzi 45 Mar 22 16:03 /yunzhongzi
总结:啥也干不了
3.x权限对目录的作用
[root@yunzhongziedu ~]# chmod u=x /yunzhongzi
[root@yunzhongziedu ~]#  ll -d /yunzhongzi
d--xr-xr-x 2 yunzhongzi yunzhongzi 45 Mar 22 16:03 /yunzhongzi
总结:可以进入目录下 无其他权限
总结:
1.如果想要正常对文件进行查看写入权限 目录必须有:r和x权限
2.如果想要在目录下创建 移动 删除操作,目录必须有:rwx权限

5、Linux系统默认权限

默认创建文件: 644  rw-r--r--
默认创建目录: 755  rwxr-xr-x
系统通过UMASK值控制默认的创建权限:
1.查看UMASK
umask回车
[root@yunzhongziedu ~]# umask
0022
用文件最高的权限减去UMASK默认的值等于默认创建文件的权限:
    666
-   022
=   644 默认文件权限
默认目录权限
    777
-   022
=   755
注意:如果UMASK值里有技术为,则文件需要相减后加1
    目录不需要加1
    比如: 设置umask值032
则默认文件权限为:
 666-032
 =634
 +010
 =644
2.修改UMASK值 临时
[root@yunzhongziedu ~]# umask
0022
[root@yunzhongziedu ~]#  umask 044
[root@yunzhongziedu ~]# umask
0044
[root@yunzhongziedu ~]# rm -rf *
[root@yunzhongziedu ~]# touch 1.txt
[root@yunzhongziedu ~]# ll
total 0
-rw--w--w- 1 root root 0 Mar 22 17:26 1.txt
[root@yunzhongziedu ~]# mkdir yunzhongzi
[root@yunzhongziedu ~]# ll
total 0
-rw--w--w- 1 root root 0 Mar 22 17:26 1.txt
drwx-wx-wx 2 root root 6 Mar 22 17:26 yunzhongzi
笔试题:如果默认创建000属性文件请问UMSAK值是多少
umask: 666

6、隐藏权限

作用:保护系统文件安全
1.查看文件隐藏权限
[root@yunzhongziedu ~]# lsattr 1.txt
---------------- 1.txt
2.设置隐藏权限
    i   无敌的,谁也无法对1.txt做任何操作 
    a   无敌的,但可以追加内容进去
[root@yunzhongziedu ~]# chattr +i 1.txt 
[root@yunzhongziedu ~]# lsattr 1.txt
----i----------- 1.txt
3.取消隐藏权限
[root@yunzhongziedu ~]# chattr -i 1.txt
[root@yunzhongziedu ~]# chattr +a 1.txt
[root@yunzhongziedu ~]# lsattr 1.txt
-----a---------- 1.txt
注意: 企业中除了隐藏权限无法修改文件以外,还需要注意第三方安全软件限制着文件
特殊权限位: 了解
1.suid 给文件或命令添加s权限,则拥有对应主人的权限
[root@db01 ~]# ll /usr/bin/rm
-rwxr-xr-x. 1 root root 62872 Aug 20  2019 /usr/bin/rm
[root@db01 ~]# chmod u+s /usr/bin/rm
[root@db01 ~]# ll /usr/bin/rm
-rwsr-xr-x. 1 root root 62872 Aug 20  2019 /usr/bin/rm
[root@db01 ~]# stat /usr/bin/rm
[root@db01 ~]# chmod u-s /usr/bin/rm
[root@db01 ~]# ll 
/usr/bin/rm-rwxr-xr-x. 1 root root 62872 Aug 20  2019 /usr/bin/rm
2.粘滞位 控制自己的文件只能自己管理 /tmp目录就是粘滞位权限 1777
在系统创建一个目录: 可以让任何用户在目录中创建文件

小屁吐槽

隐藏权限是很容易被忽略到的问题,小屁昨天上班的时候有个客户的服务器密码过期,修改密码失败,从pam角度,双因子认证角度,单用户修改,尝试了多种问题,直到今天下午才发现,用户的/etc/passwd文件权限为:
[root@yunzhongziedu ~]# lsattr /etc/passwd
----i----------- /etc/passwd
明晃晃的一个i在/etc/passwd里,之前也有问过客户有没有修改过权限,用户说没有,三个工程师也没有往这里想,结果没想到还真是这个问题,有一个i的特殊权限导致无法对这个文件做任何操作,修改密码肯定是错误的了~~~~~

小结:

1.rwx对应的数字
r   w   x
4   2   1
2.修改文件权限
  ugo  chmod ugo-x file
  数字 chmod 644 file
3.权限对于文件的作用
4.权限对于目录的作用
  都可以解决权限拒绝的问题
5.umask默认权限
6.隐藏权限位
  a  i
  lsattr
  chattr  +i file
7.特殊权限位
  s
  t

权限管理的分享到此结束,明日预告,定时任务~~~~~


想成为大佬,就要从小白开始,从0开始,一点一点的积累,慢慢成长,明天你就是大佬!!想学习更多麒麟操作系统的知识,关注小屁,让你成为运维老鸟~~~~~

### 关于 Linux Kylin 操作系统的管理员指南 #### 权限管理和系统配置概述 Linux Kylin 是基于 Debian 和 Ubuntu 开发的操作系统,因此其权限管理系统继承了许多来自这些发行版的特点。对于权限管理而言,主要依赖两个核心机制:传统的 Unix 用户/组权限模型以及更高的安全框架如 SELinux。 在 Linux 环境下,`sudo` 工具允许普通用户执行具有超用户特权的任务而不必切换整个会话到 root 账户。为了修改 `sudo` 的行为或授权策略,应当通过专门设计用于编辑 `/etc/sudoers` 文件的命令 `visudo` 进行更改[^2]。 #### 安全增强措施 针对更高层次的安全需求,可以启用 SELinux,在 2.6 版本之后的所有标准 Linux 内核中都包含了这一特性。作为由美国国家安全局开发的安全子系统,SELinux 提供了一种强制访问控制的方法来补充传统 UNIX DAC (自主访问控制)[^1]。这使得即使应用程序存在漏洞的情况下也能有效限制潜在损害范围。 #### 初始化运维常规配置 当涉及到具体实施层面时,可以从几个方面入手来进行初始设置: - **更新软件包库**:确保所有已安装程序都是最新状态。 - **创建必要的服务账号和服务组**:为不同类型的后台进程分配独立的身份凭证有助于追踪活动日志并减少攻击面。 - **调整防火墙规则和其他网络安全参数**:根据实际应用场景定制网络边界防护策略。 #### 实践中的自动化脚本应用 考虑到日常维护工作的效率问题,编写 shell 脚本来自动完成一系列常见的安全强化步骤是非常有益的做法。例如,有经验丰富的工程师已经整理了一份适用于 CentOS 7 的安全加固脚本[^3];虽然这份资源并非专门为 Linux Kylin 设计,但由于两者之间的相似性,许多概念和技术细节仍然具备参考价值。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值