zoukankan      html  css  js  c++  java
  • linux 文件 s 权限

    s权限的作用:表示对文件具用可执行权限的用户将使用文件拥有者的权限或文件拥有者所在组的权限在对文件进行执行。

    s权限的设置:4,用户拥有者的执行权限位, 6,用户组的执行权限位, 2, 两者都设置,  0, 两者都不设置。

    假设有文件a

    -rw-rw---- 1 tony tony 4 Apr 10 21:27 a

        tony用户拥有此文件,文件权限如上行。

    有程序如下test.cpp:

    #include<fstream>
    #include<iostream>
    using namespace std;
    int main()
    {
        fstream s("./a", ios::in|ios::out);
        s<<"123"<<endl;
    }
    

    可执行文件为test, 其权限为
    -rwxrwx--x 1 tony tony 13712 Apr 10 21:11 test

    tony@ubuntu:~/test$ su shw
    Password: 
    shw@ubuntu:/home/tony/test$ ls
    a  test  test.cpp
    shw@ubuntu:/home/tony/test$ ls -l test
    -rwxrwx--x 1 tony tony 13712 Apr 15 16:11 test
    shw@ubuntu:/home/tony/test$ 

    现切换到用户shw, 此用户不在tony组,对于test具有可执行权限,对a没有任何权限。

    此时用shw来执行test会发生什么呢?

    执行后查看文件 a,发现a 没有被写会任何内容。

         也就是说shw虽然对test有可执行权限,但是shw对a没有写的权限,故执行失败。

    这时有三个办法来解决:

          1.  用超级用户来执行,           不安全

          2.  使用test对a具有相应权限,         但如何test操作了n个文件 , 则需要对这n个文件都修改权限。

          3.   s权限。

     

    现在来设置s权限,使shw在执行test时使用tony的权限。

    tony@ubuntu:~/test$ chmod 4771 test
    tony@ubuntu:~/test$ ls -l
    total 24
    -rw-rw---- 1 tony tony     4 Apr 15 16:27 a
    -rwsrwx--x 1 tony tony 13712 Apr 15 16:11 test
    -rw-rw-r-- 1 tony tony   133 Apr 15 16:11 test.cpp
    tony@ubuntu:~/test$ 

    此时test的执行权限位为s。

    再使用shw来执行test, 查看文件a , 发现123已写入。

  • 相关阅读:
    DMZ区
    集群(cluster)和高可用性(HA)的概念
    JS禁用右键,禁用打印,防止另存为,IE浏览器识别(转载)
    window.open实现模式窗口(只弹出一个window.open)
    Textarea自适应高度 JS实现,兼容IE67891011
    JQ基础语法
    SQL 小笔记
    CSS样式笔记
    IE8下 Select文字垂直居中的办法
    汉字转全拼音函数优化方案(SQLServer),值得你看看
  • 原文地址:https://www.cnblogs.com/someone9/p/8551010.html
Copyright © 2011-2022 走看看