zoukankan      html  css  js  c++  java
  • linux中suid/sgid/sticky及扩展属性(attr)

    suid只适用于命令文件.(/usr/bin/passwd)

    当命令文件上有suid权限时,则操作用户的权限变成属主权限。命令文件上无suid权限则操作用户的权限不变。

    查看suid权限:

    [root@localhost ha]# which passwd

    /usr/bin/passwd

    [root@localhost ha]# ll -d /usr/bin/passwd 

    -rwsr-xr-x. 1 root root 27832 Jun 10  2014 /usr/bin/passwd

    说明:  -  + suid= S  x + suid =s(故注意sS的区别)

    当是s是说明是x+suid/sgid组成.当是S,说明是-,不是可执行文件,设置不设置suidsgid无意义.

    [test@localhost ~]$ cat /etc/shadow

    cat: /etc/shadow: Permission denied         ----无权限。

    [test@localhost ~]$ which cat

    /bin/cat

    [test@localhost ~]$ ll -d /bin/cat

    -rwxr-xr-x. 1 root root 54080 Nov  6  2016 /bin/cat

    [root@localhost ~]# chmod u+s /bin/cat

    [root@localhost ~]# ll -d /bin/cat

    -rwsr-xr-x. 1 root root 54080 Nov  6  2016 /bin/cat

    [test@localhost ~]$ cat  /etc/shadow         ----有权限,可以查看。

    sgid:适用于命令文件和目录文件。设置给命令文件时,用户权限变成属组成员的权限。设置给目录时,属组跟随。即:若用户在此目录下拥有w权限,则用户所创建的新文件的用户组与该目录的用户组相同。

    [root@localhost test]# chmod g+s ha

    [root@localhost test]# ll -d ha

    drwxr-sr-x 2 lbg lbg 24 Oct  3 18:01 ha

    [root@localhost ha]# ll

    total 0

    -rw-r--r-- 1 lbg lbg 0 Oct  3 18:01 1

    -rw-r--r-- 1 lbg lbg 0 Oct  3 18:01 3

    [root@localhost ha]# touch 2

    [root@localhost ha]# ll

    total 0

    -rw-r--r-- 1 lbg  lbg 0 Oct  3 18:01 1

    -rw-r--r-- 1 root lbg 0 Oct  3 22:44 2          ----属组变成了lbg

    -rw-r--r-- 1 lbg  lbg 0 Oct  3 18:01 3

    sticky:在一个目录上设了sticky位后,所有的用户(除了root)都可以在这个目录下创建文件,但只能删除自己创建的文件,这就对所有用户能写的目录下的用户文件启到了保护的作用。

    [root@localhost test]# ls

    a.dir

    [root@localhost test]# chmod o+t a.dir

    [root@localhost test]# ll

    drwxr-xr-t 2 root root 6 Oct  3 22:48 a.dir   

    [test@localhost a.dir]$ ll

    total 0

    -rwxrwxrwx 1 test  test  0 Oct  3 22:50 1

    -rwxrwxrwx 1 test  test  0 Oct  3 22:51 2

    -rwxrwxrwx 1 test2 test2 0 Oct  3 22:51 3

    -rwxrwxrwx 1 test2 test2 0 Oct  3 22:51 4

    [test@localhost a.dir]$ rm -fr 3

    rm: cannot remove ?.?. Operation not permitted

    用数字表示权限:

    suid =4  sgid=2  sticky =1  写在ugo权限前.

    [test@localhost test]$ ll -d b.dir/

    drwxrwxr-x 2 test test  6 Oct  3 22:55 b.dir

    [test@localhost test]$ chmod 7666 b.dir/

    [test@localhost test]$ ll -d b.dir/

    drwSrwSrwT 2 test test  6 Oct  3 22:55 b.dir

    文件扩展属性:又称隐藏权限.(attr   attribute 属性的缩写.)

    作用:防止root用户误操作删除文件。

    查看文件属性:lsattr

    [root@localhost test]# lsattr a.dir/

    ---------------- a.dir/1

    修改扩展属性:

    “+文件属性 就是添加该属性

    “-文件属性去掉此属性

    “=文件属性 此文件有且只有这属性

    chattr +a   file_name  --  +a表示不能删不能清,原内容不能变,只能追加.一般是日志文件.

    chattr +i  file_name  --  +i 表示对文件不能做任何操作.加了后可以用 - i 取消.一般是配置文件

     

  • 相关阅读:
    模式识别之检索---Bag of visual word(词袋模型)
    模式识别之knn---KNN(k-nearest neighbor algorithm)--从原理到实现
    目标跟踪之meanshift---meanshift2
    图像处理之增强---图像模糊检测
    模式识别之非参数估计---非参估计中的核函数
    haproxy文章
    nginx 有关防盗链的设置
    haproxy 关闭ssl3
    navicat 在写存储过程的时候总是说语法错误
    开源的报表系统easyreport的部署
  • 原文地址:https://www.cnblogs.com/lbg-database/p/10109975.html
Copyright © 2011-2022 走看看