/bin/su -rws-r-xr-x 1 root root
注意看到没有那个s权限是什么呢?s就是SetUID的标识,该 设置使文件在执行阶段时其有效用户id(可以通过g etuid()取得 )为该文件拥有者的id,。 而内核检查一个进程是否具有访问某权限时,是使用进程的有效用户 ID 来进行检查的,因而 使其在执行阶段具有文件所有者的权限.。典型的就是su文件。 还有一点就是当其它用户使用带用Setuid标识的命令时,自己对此命令也必需有X(执行)的权限,否则一切都免谈..这点应该不难理解的..^_^ 在linux中,文件的权限除了了常见的rwxrwxrwx权限,还有以下标识用于表示权限: setuid: 该 设置使文件在执行阶段时其有效用户id(可以通过 g etuid()取得 )为该文件拥有者的id,。 而内核检查一个进程是否具有访问某权限时,是使用进程的有效用户 ID 来进行检查的,因而 使其在执行阶段具有文件所有者的权限.。典型的就是su文件。 setgid: 该权限只对目录有效. 目录被设置该位后, 任何用户在此目录下创建的文件都具有和该目录所属的组相同的组. sticky bit: 该位可以理解为防删除位. 一个文件是否可以被某用户删除, 主要取决于该文件所属的组是否对该用户具有写权限. 如果没有写权限, 则这个目录下的所有文件都不能被删除, 同时也不能添加新的文件. 如果希望用户能够添加文件但同时不能删除文件, 则可以对文件使用sticky bit位. 设置该位后, 就算用户对目录具有写权限, 也不能删除该文件. 下面说一下如何操作这些标志: 操作这些标志与操作文件权限的命令是一样的, 都是 chmod. 有两种方法来操作, 1) chmod u+s temp -- 为temp文件加上setuid标志. (setuid 只对文件有效) chmod g+s tempdir -- 为tempdir目录加上setgid标志 (setgid 只对目录有效) chmod o+t temp -- 为temp文件加上sticky标志 (sticky只对文件有效) 实例1 @ubuntu:~/share/temp$ touch test.exe robin@ubuntu:~/share/temp$ ls -l -rw-r--r-- 1 robin robin 0 2013-09-02 15:26 test.exe robin@ubuntu:~/share/temp$ chmod u+s test.exe robin@ubuntu:~/share/temp$ ls -l -rwSr--r-- 1 robin robin 0 2013-09-02 15:26 test.exe robin@ubuntu:~/share/temp$ chmod o+s test.exe robin@ubuntu:~/share/temp$ ls -l -rwSr--r-- 1 robin robin 0 2013-09-02 15:26 test.exe 实例2 robin@ubuntu:~/share/temp$ rm test.exe robin@ubuntu:~/share/temp$ touch test.exe robin@ubuntu:~/share/temp$ ls -l -rw-r--r-- 1 robin robin 0 2013-09-02 15:28 test.exe robin@ubuntu:~/share/temp$ chmod a+t test.exe robin@ubuntu:~/share/temp$ ls -l -rw-r--r-T 1 robin robin 0 2013-09-02 15:28 test.exe 实例3 robin@ubuntu:~/share/temp$ rm test.exe robin@ubuntu:~/share/temp$ mkdir testdir robin@ubuntu:~/share/temp$ ls -l drwxr-xr-x 2 robin robin 4096 2013-09-02 15:29 testdir robin@ubuntu:~/share/temp$ su 密码: root@ubuntu:/home/robin/share/temp# ls -l drwxr-xr-x 2 robin robin 4096 2013-09-02 15:29 testdir root@ubuntu:/home/robin/share/temp# cd testdir root@ubuntu:/home/robin/share/temp/testdir# ls root@ubuntu:/home/robin/share/temp/testdir# touch 1.txt root@ubuntu:/home/robin/share/temp/testdir# ls -l -rw-r--r-- 1 root root 0 2013-09-02 15:30 1.txt root@ubuntu:/home/robin/share/temp/testdir# exit exit robin@ubuntu:~/share/temp$ chmod g+s testdir robin@ubuntu:~/share/temp$ ls -l drwxr-sr-x 2 robin robin 4096 2013-09-02 15:30 testdir robin@ubuntu:~/share/temp$ su 密码: root@ubuntu:/home/robin/share/temp# cd testdir root@ubuntu:/home/robin/share/temp/testdir# ls 1.txt root@ubuntu:/home/robin/share/temp/testdir# touch 2.txt root@ubuntu:/home/robin/share/temp/testdir# ls -l -rw-r--r-- 1 root root 0 2013-09-02 15:30 1.txt -rw-r--r-- 1 root robin 0 2013-09-02 15:31 2.txt 实例4 robin@ubuntu:~/share/temp/temp$ touch 1.exe robin@ubuntu:~/share/temp/temp$ ls -l -rw-r--r-- 1 robin robin 0 2013-09-02 15:48 1.exe robin@ubuntu:~/share/temp/temp$ chmod 7 777 1.exe robin@ubuntu:~/share/temp/temp$ ls -l -rwsrwsrwt 1 robin robin 0 2013-09-02 15:48 1.exe 结束!