linux中suid/sgid/sticky及扩展属性(attr)

摘要:
Suid仅适用于命令文件。当命令文件上有suid权限时,操作用户的权限将成为主权限。如果命令文件上没有suid权限,则操作用户的权限保持不变。查看suid权限:[root@localhostha]#whichpasswd/usr/bin/passwd[root@localhostha]#Ll-d/usr/bin/passwd-rwsr-x-1root27832Jun102014/usr/bin/passwd描述:-+suid=S,而当x+suid=S为S时,表示它由x+suid/sgid组成。当它是S时,表示它是-,而不是可执行文件。设置非suid和sgid[test@localhost~]$cat/etc/shadowcat:/etc/shadow:权限被拒绝---无权限。[ test@localhost~]$whichcat/bin/cat[test@localhost~]$ll-d/bin/cat-rwxr-xr-x.1root54080Nov62016/bin/cat[root@localhost~]#chmodu+s/bin/cat[root@localhost~]#ll-d/bin/cat-rwsr-xr-x.1root54080Nov62016/bin/cat[test@localhost~]$cat/etc/shadow----获得许可后,您可以查看它。

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 取消.一般是配置文件

 

免责声明:文章转载自《linux中suid/sgid/sticky及扩展属性(attr)》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇linux系统修改系统时间与时区zabbix监控mysql以及其他常见下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

编译 FFmpeg h263 decoder出现编译错误undefined reference to `ff_find_pix_fmt'

FFmpeg 源代码使用 RockPlayer 提供的代码和编译脚本,点击这里下载。 configure 仅保留 h263 相关的 parser demuxer decoder 以及libswscale --enable-decoder=h263 \ --enable-parser=h263 \ --enable-demuxer=h263 \ 编译出现如...

Linux系统中的以太网连接

1.在Linux中,以太网连接接口被命令为:eth0,eth1等,其中0,1表示网卡编号。 2.lspci来查看网卡硬件信息(USB则是lsusb) 3.ifconfig来查看接口信息   ifconfig -a来查看所有接口   ifconfig eth0来查看特定eth0接口信息。   ifup和ifdown来启用或者是禁用一个解口。如:ifup et...

Linux grep命令 -- 三剑客老三

常用选项   -E :开启扩展(Extend)的正则表达式。   -i :忽略大小写(ignore case)。   -v :反过来(invert),只打印没有匹配的,而匹配的反而不打印。   -n :显示行号   -w :被匹配的文本只能是单词,而不能是单词中的某一部分。   -c :显示总共有多少行被匹配到了,而不是显示被匹配到的内容,注意如果同时使用...

Linux基础学习 | gcc、g++的安装和使用

安装gcc 1、apt-get命令是debain Linux发新版的APT软件包管理工具。 dabian、ubuntu、deepin等Linux系统通过以下命令:安装gcc:Shell输入sudo apt-get install gcc命令,然后回车确定就可以了。安装g++:Shell输入sudo apt-get install g++命令,回车确定。用...

Linux 主分区_扩展分区_逻辑分区

目录:   1、MBR分区介绍   2、创建主分区   3、创建扩展分区   4、创建逻辑分区   1、MBR分区介绍   1.1 分区规定:   每个磁盘设备最多4个主分区,或者3个主分区+1个扩展分区,是因为MBR(主引导记录)的分区表(主分区表)只能存放4个分区 (GPT分区没有这个限制)。   扩展分区只能有一个。   逻辑分区可以有多个。   可...

Linux服务器上安装织梦CMS

安装篇 第一步:配置防火墙(默认情况下,端口80和3306是拒绝访问的,在防火墙上进行配置): vi/etc/sysconfig/iptables(在"COMMIT"的上一行加上如下两句) -AINPUT-mstate--stateNEW-mtcp-ptcp--dport80-jACCEPT(允许80端口通过防火墙) -AINPUT-mstate--s...