zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    python全栈-Day 4
    5个步骤实现软件质量的快速提升
    如何选择正确的静态应用安全测试(SAST)解决方案?
    安全工具箱必备技术之静态分析安全测试(SAST)
    精彩回顾:2020年自动化软件测试质量峰会
    怎样才能明智地利用代码覆盖率来最大限度地提高测试效率?
    软件开发你不可不知的那些事:如何有效减轻风险和质量债务?
    敏捷开发中不为人知的小秘密,你是否深有同感?
    当AI遇上API测试 — 敏捷开发已迎来革新时代!
    面对行业分析家和敏捷专家都认可的API测试,我们为什么会望而却步?
  • 原文地址:https://www.cnblogs.com/custa/p/2972416.html
Copyright © 2011-2022 走看看