Linux学习笔记5 用户管理(2)

本文详细介绍了Linux系统中的用户权限概念,包括基本权限符、chmod命令操作实例(如添加、删除和指定权限),chown用于更改文件和目录的所有权,以及umask的作用。还讨论了目录权限和文件的特殊权限设置,如目录的可执行权限和特权模式。
摘要由CSDN通过智能技术生成

linux用户权限:
    
    普通权限:
        r : 表示只读    4    
        w : 表示只写    2
        x : 表示可执行    1
        - : 表示无权限    0

        7 => rwx
        6 => rw-
        5 => r-x
        4 => r--
        3 => -wx
        2 => -w-
        1 => --x
        0 => ---
    用户:
        属主:    u
        属组:    g
        其他用户: o
        所有用户: a

    设定权限:chmod
        
        案例1:属主添加一个x权限
            [root@localhost test]# ll
            总计 0
            -rw-r--r-- 1 root root 0 01-06 11:40 a.txt
            [root@localhost test]# chmod u+x a.txt
            [root@localhost test]# ll
            总计 0
            -rwxr--r-- 1 root root 0 01-06 11:40 a.txt

        案例2:属组删除r权限
            [root@localhost test]# ll
            总计 0
            -rwxr--r-- 1 root root 0 01-06 11:40 a.txt
            [root@localhost test]# chmod g-r a.txt
            [root@localhost test]# ll
            总计 0
            -rwx---r-- 1 root root 0 01-06 11:40 a.txt

        案例3 : 其他用户设定w权限
            [root@localhost test]# ll
            总计 0
            -rwx---r-- 1 root root 0 01-06 11:40 a.txt
            [root@localhost test]# chmod o=w a.txt
            [root@localhost test]# ll
            总计 0
            -rwx----w- 1 root root 0 01-06 11:40 a.txt
        
        案例4 :所有的用户指定可读可执行权限
            [root@localhost test]# ll
            总计 0
            -rwx----w- 1 root root 0 01-06 11:40 a.txt
            [root@localhost test]# chmod a=rx a.txt
            [root@localhost test]# ll
            总计 0
            -r-xr-xr-x 1 root root 0 01-06 11:40 a.txt

        案例4:属主给可读可写可执行,属组给可读可执行权限,其他用户给只读权限
            [root@localhost test]# ll
            总计 0
            -r-xr-xr-x 1 root root 0 01-06 11:40 a.txt
            [root@localhost test]# chmod u=rwx,g=rx,o=r a.txt
            [root@localhost test]# ll
            总计 0
            -rwxr-xr-- 1 root root 0 01-06 11:40 a.txt
        案例5 : 数字表示方式            
            [root@localhost test]# ll
            总计 0
            ---------- 1 root root 0 01-06 11:40 a.txt
            [root@localhost test]# chmod 0754 a.txt
            [root@localhost test]# ll
            总计 0
            -rwxr-xr-- 1 root root 0 01-06 11:40 a.txt

        ==============================
        指定属主和属组 :chown
        
        案例1 :指定属主
            [root@localhost test]# ll
            总计 0
            -rwxr-xr-- 1 root root 0 01-06 11:40 a.txt
            [root@localhost test]# chown lisi a.txt
            [root@localhost test]# ll
            总计 0
            -rwxr-xr-- 1 lisi root 0 01-06 11:40 a.txt

        案例2 :指定属组
            [root@localhost test]# ll
            总计 0
            -rwxr-xr-- 1 lisi root 0 01-06 11:40 a.txt
            [root@localhost test]# chown :admin a.txt
            [root@localhost test]# ll
            总计 0
            -rwxr-xr-- 1 lisi admin 0 01-06 11:40 a.txt

        案例3:属主和属组都改变
            [root@localhost test]# ll
            总计 0
            -rwxr-xr-- 1 lisi admin 0 01-06 11:40 a.txt
            [root@localhost test]# chown root:student a.txt
            [root@localhost test]# ll
            总计 0
            -rwxr-xr-- 1 root student 0 01-06 11:40 a.txt

    
    练习:
        创建目录/share
        root用户有读写执行的权限
        student lisi xiaohua 用户有可读可执行权限
        其他用户只读的权限。

        1 创建目录
            mkdir /share
        
        2 创建用户
            useradd student
            useradd lisi
            useradd xiaohua

        3 创建组
            groupadd admin

        4 把用户指定同一个组中
            gpasswd -a student admin
            gpasswd -a lisi admin
            gpasswd -a xiaohua admin

        5 指定属主和属组
            chown root:admin /share

        6 指定权限
            chmod 754 /share
=========================================
创建文件:
    0644:
创建目录:
    0755:

默认权限:umask
    [root@localhost test]# umask
    0022

最高权限:0777
    file = 0666 - umask
    file = 0666 & (~umask)
    
    110 110 110
    000 010 010

    110 110 110
    111 101 101
    110 100 100 => 644

    dir  = 0777 - umask
    dir  = 0777 & (~umask)


临时指定umask
    [root@localhost test]# umask
    0022
    [root@localhost test]# umask 0222
    [root@localhost test]# umask
    0222

永久有效
    vim ~/.bashrc

    最后添加如下一行
        umask 0222
    

===============================================
高级特权:
    属主设定特权:
        对文件:对二进制可执行文件
        案例:
            [root@localhost test]# ll /sbin/fdisk  查看权限
            -rwxr-xr-x 1 root root 96148 2010-01-07 /sbin/fdisk
            
            [root@localhost test]# chmod 04755 /sbin/fdisk 指定特权
            [root@localhost test]# ll /sbin/fdisk
            -rwsr-xr-x 1 root root 96148 2010-01-07 /sbin/fdisk

            [root@localhost test]# chmod 0755 /sbin/fdisk 指定默认
            [root@localhost test]# ll /sbin/fdisk
            -rwxr-xr-x 1 root root 96148 2010-01-07 /sbin/fdisk

            [root@localhost test]# chmod u+s /sbin/fdisk 指定特权
            [root@localhost test]# ll /sbin/fdisk
            -rwsr-xr-x 1 root root 96148 2010-01-07 /sbin/fdisk

        属主添加特权目的是为了普通用户在执行管理员命令(绝对路径),就会委托管理员来执行这条指令。

        对目录: 不适用
    ======================
    属组设定特权:
        对文件:不适用
        对目录:
            案例:
            [root@localhost test]# chmod 02557 /share/
            [root@localhost test]# ll -d /share/
            dr-xr-srwx 2 root root 4096 01-06 14:41 /share/
            [root@localhost test]# chmod g+s /share/
            
            无论那个用户在当前目录创建文件或者目录,都归当前目录属组所有。
    ======================
    其他用户特权:
        对文件:不适用
        对目录:
            案例:
            [root@localhost test]# ll /share/ -d
            drwxr-xr-x 2 root root 4096 01-06 14:50 /share/
            [root@localhost test]# chmod 01755 /share/
            [root@localhost test]# ll /share/ -d
            drwxr-xr-t 2 root root 4096 01-06 14:50 /share/
            [root@localhost test]# chmod o+t /share/
            [root@localhost test]# ll /share/ -d
            drwxr-xr-t 2 root root 4096 01-06 14:50 /share/

            不同用户创建文件或者目录,只能当前用户修改或者删除,其他用户只能查看,不可以修改和删除。

  • 8
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值