chmod命令(chmod函数)自动清除设置用户ID位和设置组ID位

《UNIX环境高级编程(第2版)》 4.9节

1.chmod自动清除“设置组ID位”
user3@SuSE11SP2-1:/home/user1/setgid> id
uid=1003(user3) gid=1003(group3) groups=1003(group3),16(dialout),33(video)
user3@SuSE11SP2-1:/home/user1/setgid>
user3@SuSE11SP2-1:/home/user1/setgid> ls -ld .
drwxr-srwx 2 user1 users 4096 Mar 20 12:40 .
user3@SuSE11SP2-1:/home/user1/setgid>
user3@SuSE11SP2-1:/home/user1/setgid> mkdir base_user3
user3@SuSE11SP2-1:/home/user1/setgid>
user3@SuSE11SP2-1:/home/user1/setgid> ls -ld base_user3/
drwxr-sr-x 2 user3 users 4096 Mar 20 12:40 base_user3/    # 设置组ID位生效,并且创建的目录继承了该位
user3@SuSE11SP2-1:/home/user1/setgid>
user3@SuSE11SP2-1:/home/user1/setgid> mkdir base_user3/sub_user3
user3@SuSE11SP2-1:/home/user1/setgid>
user3@SuSE11SP2-1:/home/user1/setgid> ls -ld base_user3/sub_user3/
drwxr-sr-x 2 user3 users 4096 Mar 20 12:41 base_user3/sub_user3/    # 继承的“设置组ID位”生效
user3@SuSE11SP2-1:/home/user1/setgid>
user3@SuSE11SP2-1:/home/user1/setgid> chmod o-x base_user3/
user3@SuSE11SP2-1:/home/user1/setgid>
user3@SuSE11SP2-1:/home/user1/setgid> ls -ld base_user3/
drwxr-xr-- 3 user3 users 4096 Mar 20 12:41 base_user3/    # 设置组ID位被自动关闭了
user3@SuSE11SP2-1:/home/user1/setgid>
user3@SuSE11SP2-1:/home/user1/setgid> mkdir base_user3/sub_user3.new
user3@SuSE11SP2-1:/home/user1/setgid>
user3@SuSE11SP2-1:/home/user1/setgid> ls -l base_user3/
total 8
drwxr-sr-x 2 user3 users  4096 Mar 20 12:41 sub_user3
drwxr-xr-x 2 user3 group3 4096 Mar 20 12:42 sub_user3.new
user3@SuSE11SP2-1:/home/user1/setgid>

2.写文件时,自动清除“设置用户ID位”
user3@SuSE11SP2-1:/home> ls -l setuid.txt
-rwSr--rw- 1 root root 0 Mar 20 13:05 setuid.txt
user3@SuSE11SP2-1:/home>
user3@SuSE11SP2-1:/home> echo "hello" >setuid.txt
user3@SuSE11SP2-1:/home>
user3@SuSE11SP2-1:/home> ls -l setuid.txt
-rw-r--rw- 1 root root 6 Mar 20 13:07 setuid.txt    # 设置用户ID位被清除
user3@SuSE11SP2-1:/home>
user3@SuSE11SP2-1:/home> ls -l setgid.txt
-rw-r-Srw- 1 root root 0 Mar 20 13:07 setgid.txt
user3@SuSE11SP2-1:/home>
user3@SuSE11SP2-1:/home> echo "hello" >setgid.txt
user3@SuSE11SP2-1:/home>
user3@SuSE11SP2-1:/home> ls -l setgid.txt
-rw-r-Srw- 1 root root 6 Mar 20 13:08 setgid.txt    # 设置ID位未被清除
user3@SuSE11SP2-1:/home>
user3@SuSE11SP2-1:/home> cat setgid.txt
hello

 

 

转载于:https://www.cnblogs.com/custa/archive/2013/03/21/2972416.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值