0
点赞
收藏
分享

微信扫一扫

Linux 权限管理 学习总结(一)

sunflower821 2022-04-30 阅读 90

Linux 基本权限 和 umask默认权限 学习总结

一、前言:

        传统印象中,相较于windows系统,Linux系统对于权限管理更加重视,因为在实际角色分配时,分配权限是必不可少的一环。有多少权限干多少事,权限分配的越详细,安全性越高,所以对于运维来讲,掌握权限管理是必须的。

        在写权限之前,先简单说下Linux用户角色。

二、用户角色:

        Linux系统中,用户拥有不同角色,主要分类三类:超级管理员(root)、伪用户、和普通用户。

        知道普通用户是权限分配的主角,接下来就聊一下用户权限。

三、用户权限:

        说了用户权限,再说说权限的分类。       

四、权限分类:

        在进阶高级之前,权限管理主要分为六大类:

        前面介绍了六大权限的分类、今天重点总结前两类:基本权限  和 默认权限umask。

五、基本权限

5.1 权限位的含义

 5.1.1 引例

5.1.2 权限位含义

5.2 权限含义的解释

 5.2.1、权限对文件的作用        

5.2.2、权限对于目录的作用       

5.3、权限命令 chmod

5.3.1 命令格式

[root@localhost ~]# chmod [选项] 权限模式 文件名/目录
[选项]
    -R :递归设置权限,给子目录下所有文件设置权限

5.3.2 权限模式

举例:为 suidcheck.sh 所有者删除写权限(-w),所属组增加写权限(+w),其他人增加读权限 (+r

[root@localhost ~]# ll suidcheck.sh 
-rwxr--r--. 1 root root 652 4月  27 14:00 suidcheck.sh
[root@localhost ~]# chmod u-w,g+w,o+r suidcheck.sh 
[root@localhost ~]# ll suidcheck.sh 
-r-xrw-r--. 1 root root 652 4月  27 14:00 suidcheck.sh

5.3.3 数字权限

5.3.4 用法举例

举例1:为文件  suidcheck.sh 赋予 755 权限

[root@localhost ~]# chmod 755 suidcheck.sh 
[root@localhost ~]# ll suidcheck.sh 
-rwxr-xr-x. 1 root root 652 4月  27 14:00 suidcheck.sh

举例2:还原 suidcheck.sh 为最初权限 744 

[root@localhost ~]# chmod 744 suidcheck.sh 
[root@localhost ~]# ll suidcheck.sh 
-rwxr--r--. 1 root root 652 4月  27 14:00 suidcheck.sh

举例3:综合举例。在 /root 目录下,创建 test 子目录,并在 test 子目录下创建两个测试文件 test1.txttest2.txt ,递归设置 test 子目录权限为 754 (-rwxr-xr--.)

#查看当前所在目录
[root@localhost ~]# pwd
/root
#创建子目录 test
[root@localhost ~]# mkdir test
#查看 test 子目录是否创建成功
[root@localhost ~]# ls
anaconda-ks.cfg  install.log  install.log.syslog  suidcheck.sh  suid.list  suid_log_2022-04-27  test
#进入 test 子目录
[root@localhost ~]# cd test
#创建测试文件 test1.txt 和 test2.txt
[root@localhost test]# touch test1.txt test2.txt
#查看创建的测试文件
[root@localhost test]# ls
test1.txt  test2.txt
#返回到 /root 目录下
[root@localhost test]# cd
# 查看当前子目录 test 权限
[root@localhost ~]# ll -d test
#当前目录权限是 755
drwxr-xr-x. 2 root root 4096 4月  29 19:00 test
#查看子目录 test 的测试文件权限
[root@localhost ~]# ll test
#测试文件权限都是 644
总用量 0
-rw-r--r--. 1 root root 0 4月  29 19:00 test1.txt
-rw-r--r--. 1 root root 0 4月  29 19:00 test2.txt
#递归设置子目录 test 的权限为 754
[root@localhost ~]# chmod -R 754 test
[root@localhost ~]# ll -d test
drwxr-xr--. 2 root root 4096 4月  29 19:00 test
[root@localhost ~]# ll test
总用量 0
-rwxr-xr--. 1 root root 0 4月  29 19:00 test1.txt
-rwxr-xr--. 1 root root 0 4月  29 19:00 test2.txt
#删除测试目录 test 和测试文件 test1.txt 和 test2.txt
[root@localhost ~]# rm -rf test
[root@localhost ~]# ls
anaconda-ks.cfg  install.log  install.log.syslog  suidcheck.sh  suid.list  suid_log_2022-04-27

六、默认权限 umask

6.1 查看当前系统的 umask 权限

#八进制显示umask权限
[root@localhost ~]# umask
0022
#用字母显示文件和目录的初始权限
[root@localhost ~]# umask -S
u=rwx,g=rx,o=rx

6.2 默认权限算法

6.2.1 默认最大权限

6.2.2 默认权限算法

 6.3 修改 umask 默认权限

 [root@localhost ~]# vi /etc/profile
 
 57 # By default, we want umask to get set. This sets it for login shell
 58 # Current threshold for system reserved uid/gids is 200
 59 # You could check uidgid reservation validity in
 60 # /usr/share/doc/setup-*/uidgid file
 61 if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
 62     umask 002
 63 else
 64     umask 022
 65 fi

七、小结

举报

相关推荐

0 条评论