本文主要是介绍linux特殊权限位之setuid、setgid和sticky,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1 2 | [root@Vmware5 ~] # ls -l /etc/passwd -rw-r--r--. 1 root root 981 Oct 25 01:00 /etc/passwd |
1 2 | [root@Vmware5 ~] # ls -l /usr/bin/passwd (s就是suid位) -rwsr-xr-x. 1 root root 30768 Feb 22 2012 /usr/bin/passwd |
1 2 3 4 5 | chmod u(+|-)s /path/somefile chmod 4664 /path/somefile 注意: s:表示属主原来有执行权限 S:表示属主原来没有执行权限 |
1 | [root@Vmware5 ~] # useradd taokey |
1 2 | [root@Vmware5 ~] # cp /etc/fstab /tmp/ [root@Vmware5 ~] # cd /tmp/ |
1 2 | [root@Vmware5 tmp] # ll fstab -rw-r--r--. 1 root root 899 Oct 25 00:16 fstab |
1 2 3 | [root@Vmware5 tmp] # chmod o-r fstab [root@Vmware5 tmp] # ll fstab -rw-r-----. 1 root root 899 Oct 25 00:16 fstab |
1 | [root@Vmware5 tmp] # su - taokey |
1 2 | [taokey@Vmware5 ~]$ cat /tmp/fstab cat : /tmp/fstab : Permission denied |
1 2 3 4 5 6 7 8 | [root@Vmware5 ~] # cp /bin/cat /tmp/ [taokey@Vmware5 tmp]$ ls -l fstab cat -rwxr-xr-x. 1 root root 45224 Oct 25 00:21 cat -rw-r-----. 1 root root 899 Oct 25 00:16 fstab [taokey@Vmware5 tmp]$ . /cat fstab . /cat : fstab: Permission denied [taokey@Vmware5 tmp]$ exit logout |
1 | [root@Vmware5 tmp] # chmod u+s cat |
1 | 添加完s权限位之后,再切换到普通用户taokey,测试是否可以成功执行 cat 命令 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | [root@Vmware5 tmp] # su - taokey [taokey@Vmware5 ~]$ cd /tmp/ [taokey@Vmware5 tmp]$ . /cat fstab # # /etc/fstab # Created by anaconda on Thu Oct 24 23:49:23 2013 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=b49ee2b3-75aa-4227-a9ff-5d0d990af0fd / ext4 defaults 1 1 UUID=3a69daa4-b393-4694-abbb-b856345b376d /boot ext4 defaults 1 2 UUID=34f85ed8-5f68-4fdc-8aa0-e50d2f9f012e /home ext4 defaults 1 2 UUID=95d97c70-9291-499b-ac16-a38508a85e4d swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 |
1 2 | [taokey@Vmware5 tmp]$ ll cat -rwsr-xr-x. 1 root root 45224 Oct 25 00:21 cat |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | 例子: [root@Vmware5 tmp] # usermod -a -G mygrp xen [root@Vmware5 tmp] # usermod -a -G mygrp kvm [root@Vmware5 tmp] # mkdir /tmp/test [root@Vmware5 tmp] # ls -ld /tmp/test/ drwxr-xr-x. 2 root root 4096 Oct 25 00:48 /tmp/test/ [root@Vmware5 tmp] # chmod g+w /tmp/test [root@Vmware5 tmp] # ls -ld /tmp/test/ drwxrwxr-x. 2 root root 4096 Oct 25 00:48 /tmp/test/ [root@Vmware5 tmp] # chown :mygrp /tmp/test [root@Vmware5 tmp] # ls -ld /tmp/test drwxrwxr-x. 2 root mygrp 4096 Oct 25 00:48 /tmp/test [root@Vmware5 ~] # su - xen [xen@Vmware5 ~]$ cd /tmp/test [xen@Vmware5 test ]$ touch a.xen [xen@Vmware5 test ]$ ls -l total 0 -rw-rw-r--. 1 xen xen 0 Oct 25 00:50 a.xen [root@Vmware5 ~] # su - kvm [kvm@Vmware5 ~]$ cd /tmp/test [kvm@Vmware5 test ]$ touch a.kvm [kvm@Vmware5 test ]$ ls -l total 0 -rw-rw-r--. 1 kvm kvm 0 Oct 25 00:51 a.kvm -rw-rw-r--. 1 xen xen 0 Oct 25 00:50 a.xen |
1 2 | [kvm@Vmware5 test ]$ echo "hello" >>a.xen - bash : a.xen: Permission denied |
1 2 3 | [root@Vmware5 ~] # chmod g+s /tmp/test [root@Vmware5 ~] # ls -ld /tmp/test drwxrwsr-x. 2 root mygrp 4096 Oct 25 00:51 /tmp/test |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | [root@Vmware5 ~] # su - xen [xen@Vmware5 test ]$ touch b.xen [xen@Vmware5 test ]$ ll b.xen -rw-rw-r--. 1 xen mygrp 0 Oct 25 01:01 b.xen [root@Vmware5 ~] # su - kvm [kvm@Vmware5 ~]$ echo "hello" >>b.xen [kvm@Vmware5 ~]$ cat b.xen hello [kvm@Vmware5 ~]$ touch b.kvm [root@Vmware5 ~] # su - xen [xen@Vmware5 ~]$ cd /tmp/test/ [xen@Vmware5 test ]$ echo "My name is taoyake." >>b.kvm [xen@Vmware5 test ]$ cat b.kvm My name is taoyake. |
1 2 3 4 5 6 7 | 例如: [xen@Vmware5 test ]$ rm b.kvm [xen@Vmware5 test ]$ ll total 0 -rw-rw-r--. 1 kvm kvm 0 Oct 25 00:51 a.kvm -rw-rw-r--. 1 xen xen 0 Oct 25 00:50 a.xen -rw-rw-r--. 1 xen mygrp 0 Oct 25 01:01 b.xen |
1 2 3 4 5 6 7 8 9 10 11 12 | 实例操作: [root@Vmware5 ~] # ls -ld /tmp/test drwxrwsr-t. 2 root mygrp 4096 Oct 25 01:10 /tmp/test [xen@Vmware5 test ]$ ls a.kvm a.xen b.xen c.kvm [xen@Vmware5 test ]$ echo "beyond" >>c.kvm [xen@Vmware5 test ]$ cat c.kvm beyond [xen@Vmware5 test ]$ echo "" >c.kvm [xen@Vmware5 test ]$ cat c.kvm [xen@Vmware5 test ]$ rm -rf c.kvm rm : cannot remove `c.kvm': Operation not permitted |
1 2 3 4 5 6 7 8 9 10 11 | [kvm@Vmware5 test ]$ touch c.kvm [kvm@Vmware5 test ]$ ls a.kvm a.xen b.xen c.kvm [kvm@Vmware5 test ]$ rm c.kvm [kvm@Vmware5 test ]$ ls a.kvm a.xen b.xen [xen@Vmware5 test ]$ ll total 0 -rw-rw-r--. 1 kvm kvm 0 Oct 25 00:51 a.kvm -rw-rw-r--. 1 xen xen 0 Oct 25 00:50 a.xen -rw-rw-r--. 1 xen mygrp 0 Oct 25 01:01 b.xen |
这篇关于linux特殊权限位之setuid、setgid和sticky的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!