linux下的权限掩码,linux查看用户的umask命令权限掩码022特殊权限

umask命令用来设置限制新建文件权限的掩码。当新文件被创建时,其最初的权限由文件创建掩码决定。用户每次注册进入系统时,umask命令都被执行, 并自动设置掩码mode来限制新文件的权限。

语法

umask(选项)(参数)

选项

-p:输出的权限掩码可直接作为指令来执行;

-S:以符号方式输出权限掩码。

作用;

控制新建的文件或目录的权限

系统用户:#umask 022

普通用户:#umask 002

umask值与新建文件、目录权限对照表

umask值

目录权限值

文件权限值

0

7

6

1

6

6

2

5

4

3

4

4

4

3

2

5

2

2

6

1

0

7

0

0

例:

设置系统的权限掩码为444[root@xuegod163 ~]#umask 444

以符号的格式设置umask:用户所有者读取、组群所有者写入、其他用户读取[root@xuegod163 ~]#umask  u=r,g=w,o=r

查看系统当前的umask设置[root@xuegod163 ~]#umask

0353以符号的格式显示当前的umask设置

[root@xuegod163 ~]#umask -S

u=r,g=w,o=r

计算方法:

文件默认权限=666-umask值 666-022=644

目录默认权限=777-umask 值 777-022=755

#这是一个好的记忆方法,但不严谨。

/etc/bashrc

if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then # id -gn显示组名,id -un 显示用户名

umask 002 #普通用户

else

umask 022 #系统用户

fi

特殊权限:

SUID    SGID    Stickybit

s对应的数值为:u 4,g 2,t 1

SUID:

限定:只能设置在二进制可执行程序上面。对目录文本设置无效。

功能:程序运行时的权限从执行者变更成程序所有者。

[root@xuegod163 ~]# ll /usr/bin/passwd

-rwsr-xr-x. 1 root root 30768 Feb 17 2012 /usr/bin/passwd

[root@xuegod163 ~]# useradd canxue

[root@xuegod163 ~]# su - canxue

[canxue@xuegod163 ~]$ less /etc/shadow

/etc/shadow: 权限不够

解决方法

[root@xuegod163 ~]# ll /usr/bin/less

-rwxr-xr-x 1 root root 154416 Sep 26 2011 /usr/bin/less

[root@xuegod163 ~]# chmod u+s /usr/bin/less

[root@xuegod163 ~]# ll /usr/bin/less

-rwsr-xr-x 1 root root 154416 Sep 26 2011 /usr/bin/less

验证

[canxue@xuegod163 ~]$ less /etc/shadow 成功读取

注意:

[root@xuegod163 ~]# chmod 4755 /usr/bin/less 等同于

[root@xuegod163 ~]# chmod u+s /usr/bin/less

SGID:

限定:既可以给二进制可执行程序设置,也可以给目录设置。

功能:在设置了SGID权限的目录下建立文件时,新创建的文件的所属组会继承上级目录的所属组

[root@xuegod163 ~]# mkdir sws

[root@xuegod163 ~]# chmod g+s sws/

[root@xuegod163 ~]# cd sws/

[root@xuegod163 sws]# touch chuanshuo

[root@xuegod163 sws]# ll chuanshuo

-rw-r--r-- 1 root canxue 0 Oct 13 22:05 chuanshuo

[root@xuegod163 ~]# chmod 2755 sws/

[root@xuegod163 ~]# ll -d sws/

drwxr-sr-x 2 canxue canxue 4096 Oct 13 22:05 sws/

Stickybit

限定:只作用于目录

功能:目录下创建的文件只有root、文件创建者、目录所有者才能删除

[root@xuegod163 ~]# chmod o+t /tmp/

[root@xuegod163 ~]# ll -d /tmp/

drwxrwxrwt. 14 root root 4096 Oct 13 21:44 /tmp/

[canxue@xuegod163 tmp]$ touch canxue.txt

[canxue@xuegod163 tmp]$ chmod 777 canxue.txt

[sanfran@xuegod163 tmp]$ rm -rf canxue.txt

rm: 无法删除"canxue.txt": 不允许的操作

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值