linux下文件的特殊权限s和t
来源:互联网 发布:最好用的crm软件 编辑:程序博客网 时间:2024/05/11 11:13
先看看这两个文件的权限:
[root@localhost ~]# ls -ld /usr/bin/passwd /tmp
drwxrwxrwt 4 root root 4096 Jun 2 17:33 /tmp
-rwsr-xr-x 1 root root 22984 Jan 7 2007 /usr/bin/passwd
这里的s和t是针对执行权限来讲的。
这个s权限,是为了让一般使用者临时具有该文件所属主/组的执行权限。就比如/usr/bin/passwd在执行它的时候需要去修改/etc/passwd和/etc/shadow等文件,这些文件除了root外,其他用户都没有写权限,但是又为了能让普通用户修改自己的密码,只能时临时让他们具有root的权限。所以这个s权限就是用来完成这个特殊任务的。s权限只能应用在二进制的可执行文件上。
如果你不想让普通用户修改自己的密码,只需要
[root@localhost ~]# chmod u-s /usr/bin/passwd 或者
[root@localhost ~]# chmod 0755 /usr/bin/passwd
0755最前面的0表示不使用任何特殊权限,该位上的数字可以是0,1(--t),2(-s-),3(-st),4(s--),5(s-t),6(ss-),7(sst)
那个t权限只针对目录生效,它表示只能让所属主以及root可以删除(重命名/移动)该目录下的文件。比如/tmp目录本来就是任何用户都可以读写,如果别人可以任意删除(重命名/移动)自己的文件,那岂不是很危险。所以这个t权限就是为了解决这个麻烦的。下面举一个例子,说明一下这个权限的用法:
[root@localhost ~]# cd /tmp/
[root@localhost tmp]# mkdir test
[root@localhost tmp]# chmod 1777 test
[root@localhost tmp]# ls -ld test
drwxrwxrwt 2 root root 4096 Jun 2 18:10 test
[root@localhost tmp]# su test1
[test1@localhost tmp]$ touch test/1.txt
[test1@localhost tmp]$ ls -l test
total 4
-rw-r--r-- 1 test1 test 0 Jun 2 18:12 1.txt
[test1@localhost tmp]$ exit
[root@localhost tmp]# su www
[www@localhost tmp]$ ls -l test/1.txt
-rwxrwxrwx 1 test1 test 6 Jun 2 18:12 test/1.txt
[www@localhost tmp]$ rm test/1.txt
rm: cannot remove `test/1.txt': Operation not permitted
提示不能删除1.txt
[www@localhost tmp]$ exit
[root@localhost tmp]# chmod -t test
去掉t权限。
[root@localhost tmp]# ls -ld test
drwxrwxrwx 2 root root 4096 Jun 2 18:13 test
[root@localhost tmp]# su www
[www@localhost tmp]$ rm -f test/1.txt
再次删除,则删除成功。
[www@localhost tmp]$ ls test/1.txt
[root@localhost ~]# ls -ld /usr/bin/passwd /tmp
drwxrwxrwt 4 root root 4096 Jun 2 17:33 /tmp
-rwsr-xr-x 1 root root 22984 Jan 7 2007 /usr/bin/passwd
这里的s和t是针对执行权限来讲的。
这个s权限,是为了让一般使用者临时具有该文件所属主/组的执行权限。就比如/usr/bin/passwd在执行它的时候需要去修改/etc/passwd和/etc/shadow等文件,这些文件除了root外,其他用户都没有写权限,但是又为了能让普通用户修改自己的密码,只能时临时让他们具有root的权限。所以这个s权限就是用来完成这个特殊任务的。s权限只能应用在二进制的可执行文件上。
如果你不想让普通用户修改自己的密码,只需要
[root@localhost ~]# chmod u-s /usr/bin/passwd 或者
[root@localhost ~]# chmod 0755 /usr/bin/passwd
0755最前面的0表示不使用任何特殊权限,该位上的数字可以是0,1(--t),2(-s-),3(-st),4(s--),5(s-t),6(ss-),7(sst)
那个t权限只针对目录生效,它表示只能让所属主以及root可以删除(重命名/移动)该目录下的文件。比如/tmp目录本来就是任何用户都可以读写,如果别人可以任意删除(重命名/移动)自己的文件,那岂不是很危险。所以这个t权限就是为了解决这个麻烦的。下面举一个例子,说明一下这个权限的用法:
[root@localhost ~]# cd /tmp/
[root@localhost tmp]# mkdir test
[root@localhost tmp]# chmod 1777 test
[root@localhost tmp]# ls -ld test
drwxrwxrwt 2 root root 4096 Jun 2 18:10 test
[root@localhost tmp]# su test1
[test1@localhost tmp]$ touch test/1.txt
[test1@localhost tmp]$ ls -l test
total 4
-rw-r--r-- 1 test1 test 0 Jun 2 18:12 1.txt
[test1@localhost tmp]$ exit
[root@localhost tmp]# su www
[www@localhost tmp]$ ls -l test/1.txt
-rwxrwxrwx 1 test1 test 6 Jun 2 18:12 test/1.txt
[www@localhost tmp]$ rm test/1.txt
rm: cannot remove `test/1.txt': Operation not permitted
提示不能删除1.txt
[www@localhost tmp]$ exit
[root@localhost tmp]# chmod -t test
去掉t权限。
[root@localhost tmp]# ls -ld test
drwxrwxrwx 2 root root 4096 Jun 2 18:13 test
[root@localhost tmp]# su www
[www@localhost tmp]$ rm -f test/1.txt
再次删除,则删除成功。
[www@localhost tmp]$ ls test/1.txt
ls: test/1.txt: No such file or directory
转自:http://blog.csdn.net/kkdelta/article/details/7850669
0 0
- linux下文件的特殊权限s和t
- linux下文件的特殊权限s和t
- linux下文件的特殊权限s和t
- linux下文件的特殊权限s和t
- linux下文件的特殊权限s和t
- Linux下文件的特殊权限
- linux 下文件特殊权限
- linux下文件权限和特殊权限说明
- linux文件的文件类型(d,-,s,b,c,....)和文件权限(r,w,x, s,t,S,T)与文件特殊权限(s,t,S,T)
- linux下文件和权限的详解
- Linux下文件的权限
- linux下文件的权限
- linux下文件的权限
- linux下文件的权限
- linux下文件的权限
- linux下文件的权限
- linux下文件的权限
- linux下文件的权限
- mongoDB的操作---增删改查
- 第三十四讲项目1.3——1/2+2/3+3/4+…+19/20的总和
- 转载csdn博客的方法
- MySQL数据库加密与解密
- J2SE第八章——IO输入输出流(基本知识与IO流实现文件复制)
- linux下文件的特殊权限s和t
- 第一段C语言代码
- NOIP 2000 单词接龙ACC pascal程序加题解。
- 利用iframe实现表单的无刷新提交
- SQL多表连接查询
- 【转】Eclipse/MyEclipse 最最常用的快捷键
- Android Studio的多渠道打包
- iOS Xcode中Version和Build的区别
- 透明式状态栏和着色状态栏