linux用户权限设置_Linux之用户权限

基本权限UGO

UGO设置基本权限: 只能一个用户,一个组和其他人

权限对象:属主: u 属组: g 其他人: o 所有人:a(u+g+o)

读:r=4 写:w=2 执行: x=1

更改权限

语法 chmod   对象(u/g/o/a)赋值符(+/-/=)权限类型(r/w/x)    文件/目录

示例

[root@localhost ~]# cd  /tmp
[root@localhost ~]# touch     file1
[root@localhost tmp]# ll file1 
-rw-r--r--. 1 root root 0 4月  13 20:49 file1
    权限      属主 属组                  文件
[root@localhost tmp]# chmod u+x file1 //属主增加执行
-rwxr--r--. 1 root root 0 4月  13 20:49 file1

数字修改

4读   2写   1执行
[root@localhost ~]# chmod 644 file1
[root@localhost ~]# ll file1
-rw-r--r-- 1 alice it 17 10-25 16:45 file1

更改属主、属组

chown

语法:chown   用户名.组名   文件

示例

[root@localhost ~]# chown alice.hr file1 //改属主、属组
[root@localhost  ~]# chown alice file1 //只改属主
[root@localhost ~]# chown .hr file1 //只改属组

chgrp

语法:chgrp   组名   文件      -R是递归的意思

示例

[root@localhost ~]# chgrp it file1 //改文件属组
[root@localhost ~]# chgrp -R it dir1 //改文件属组

基本权限 ACL

ACL文件权限管理: 设置不同用户,不同的基本权限(r、w、x)。对象数量不同。

语法 setfacl -m u:alice:rw /home/test.txt

示例

[root@qianfeng ~]# touch /home/test.txt //准备文件
[root@qianfeng ~]# ll /home/test.txt 
-rw-r--r-- 1 root root 0 10-26 13:59 /home/test.txt
[root@qianfeng ~]# getfacl /home/test.txt //查看文件有哪些ACL权限
[root@qianfeng ~]# setfacl -m u:alice:rw /home/test.txt //设置用户alice权限
[root@qianfeng ~]# setfacl -m u:jack:- /home/test.txt //设置用户jack权限
[root@qianfeng ~]# setfacl -m o::rw /home/test.txt //设置其他人有读写权限

如何删除一条acl,如何删除所有acl呢?

[root@qianfeng ~]# getfacl /home/test.txt
[root@qianfeng ~]# setfacl -m g:hr:r /home/test.txt
[root@qianfeng ~]# setfacl -x g:hr /home/test.txt //删除组hr的acl权限
[root@qianfeng ~]# setfacl -b /home/test.txt //删除所有acl权限

特殊权限

特殊位 suid

suid针对文件/程序时,具备临时获得属主的权限。

为cat程序添加上suid权限。

[root@qianfeng ~]# ll  /usr/bin/cat
自行观察输出信息1
[root@qianfeng ~]# chmod u+s /usr/bin/cat
[root@qianfeng ~]# ll  /usr/bin/cat
自行观察输出信息2

使用普通用户运行cat。暂时获得root权限

[alice@qianfeng ~]$ cat /root/file1.txt
[root@qianfeng ~]# chmod u-s /usr/bin/cat
[root@qianfeng ~]# ll  /usr/bin/cat

文件属性chattr

常用于锁定某个文件,拒绝修改。

0da71800cdb2577a844d3bc70272d458.png

示例

[root@qianfeng ~]# touch file100 // 先创建新文件进行对比。查看默认权限。
[root@qianfeng ~]# lsattr file100
-------------- file100
[root@qianfeng ~]# chattr +i file100 //不能更改,重命名,删除
[root@qianfeng ~]# lsattr file100
----i--------- file100  //3 查看不同属性
[root@qianfeng ~]# rm -rf file100 //4 尝试删除失败
rm: cannot remove `file100': Operation not permitted 
[root@qianfeng ~]# chattr -i file100 //还原属性

进程掩码 umask

新建文件、目录的默认权限会受到umask的影响,umask表示要减掉的权限

修改shell umask值(临时)
[root@qianfeng ~]# umask 000
[root@qianfeng ~]# mkdir dir900
[root@qianfeng ~]# touch file900
[root@qianfeng ~]# ll -d dir900 file900 
drwxrwxrwx. 2 root root 4096 3月  11 19:44 dir900
-rw-rw-rw-. 1 root root    0 3月  11 19:44 file900
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值