Linux: uid/euid/suid的关系
三种进程用户的简单解释:
三种用户/组ID:
uid/gid: 实际用户/组ID
euid/egid: 有效用户/组ID, 进程执行某个应用的用户/组ID.
suid/sgid: 设置用户/组ID, 应用所属用户/组ID.
几者关系:
进程执行应用时根据euid/egid. 而euid/egid设置规则:
(euid,egid)=(suid,sgid)?(suid,sgid):(uid:gid);
注意: #!/xxx 之类的脚本无效, 因为这些脚本是通过bash或python等解释器执行的. 其在linux下类似
exec bash xxx, exec python xxxx...
所以, 设置chmod +s xxx是完全无效的, 如果要设置, 就去设置bash, python解释器的权限!
例如:
-rwx------ 1 hezhaowu hezhaowu 4 2014-05-20 09:54 hezhaowufile.txt
-rwxr-xr-x 1 hezhaowu hezhaowu 68 2014-05-20 09:55 test
cat test
echo 'test begin...'
cat /tmp/hezhaowufile.txt
echo 'test done...
设置suid前:
-rwxr-xr-x 1 hezhaowu hezhaowu 68 2014-05-20 09:55 test
www-data@dc26:/tmp$ ./test
test begin...
cat: /tmp/hezhaowufile.txt: Permission denied
test done...
设置suid后:
-rwsr-sr-x 1 hezhaowu hezhaowu 68 2014-05-20 09:55 test*
Linux下,对于脚本(包括perl,python)是忽略设置-用户/组ID位的!!!
---------------------------------------
使用测试的代码:
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
int main() {
printf("uid=%d,euid=%d\n", getuid(), geteuid());
exit(0);
}
测试结果:
hezhaowu@dc26:/tmp$ chmod u+s ctest
hezhaowu@dc26:/tmp$ ll ctest
-rwsr-xr-x 1 hezhaowu hezhaowu 8622 2014-05-20 11:40 ctest*
hezhaowu@dc26:/tmp$ ./ctest
uid=1007,euid=1007
www-data@dc26:/tmp$ ./ctest
uid=33,euid=1007
hezhaowu@dc26:/tmp$ chmod u-s ctest
hezhaowu@dc26:/tmp$ ll ctest
-rwxr-xr-x 1 hezhaowu hezhaowu 8622 2014-05-20 11:40 ctest*
www-data@dc26:/tmp$ ./ctest
uid=33,euid=33
可见, 对于exec调用的应用, suid的规则还是生效的.
Linux: uid/euid/suid的关系的更多相关文章
- linux uid/euid/suid
Each UNIX process has 3 UIDs associated to it. Superuser/root is UID=0. UID Read UID. It is of the u ...
- UID, EUID, SUID, FSUID
摘自:https://blog.csdn.net/wh8_2011/article/details/50825340 UID, EUID, SUID, FSUID 2016年03月08日 10:40: ...
- [代码修订版] Python 踩坑之旅 [进程篇其四] 踩透 uid euid suid gid egid sgid的坑坑洼洼
目录 1.1 踩坑案例 1.2 填坑解法 1.3 坑位分析 1.4 技术关键字 1.5 坑后思考 下期坑位预告 代码示例支持 平台: Centos 6.3 Python: 2.7.14 代码示例: 公 ...
- Python 踩坑之旅进程篇其四一次性踩透 uid euid suid gid egid sgid的坑坑洼洼
目录 1.1 踩坑案例 1.2 填坑解法 1.3 坑位分析 1.4 技术关键字 1.5 坑后思考 下期坑位预告 代码示例支持 平台: Centos 6.3 Python: 2.7.14 代码示例: 菜 ...
- 整理下本周工作中遇到的疑问;uid/euid/suid;docker镜像管理
1.系统中的父子进程关系,以及docker是如何处理的这种父子进程关系,线上问题发现,子进程长时间得不到退出. 2.调用system系统调用发生了啥事情,发现大量的页表拷贝. 3.通过shell命令通 ...
- linux UID,GID,EUID,EGID,SUID,SGID
SUID, SGID, sticky位可以参考: http://onlyzq.blog.51cto.com/1228/527247/ SUID属性只能运用在可执行文件上,当用户执行该执行文件时,会临时 ...
- Linux 特殊权限 SUID,SGID,SBIT
setuid 和 setgid 分别是 set uid ID upon execution 和 set group ID upon execution 的缩写.我们一般会再次把它们缩写为 suid 和 ...
- linux特殊权限SUID、SGID、SBIT
对于linux中文件或目录的权限,应该都知道普通的rwx权限(关于linux中rwx权限的看我的这篇博文http://www.cnblogs.com/javaee6/p/3994750.html).我 ...
- Linux特殊位SUID、SGID、SBIT
Linux特殊位SUID.SGID.SBIT 前言 Linux中的文件权限一般有x.w.r,在某个情况下有需要用到s.t,即特殊位. 进程运行时能够访问哪些资源或文件,不取决于进程文件的属主属组,而是 ...
随机推荐
- 求编译器中数的最值(c++)
#include <limits> //头文件 #include <iostream> using namespace std; int main() { cout <& ...
- [Nginx 1] Nginx简介
导读:现在项目中用到这个Nginx了,本来是想着把代码调通了就得了.想想还是花点时间总结总结,就利用门卫思维吧.今天主要是一个整体的介绍,然后在学习的过程中,接着总结Nginx的其他使用事宜. 一.什 ...
- PAT1099
/*innner order traverse for BST will be ordered *1.sort the value in buffer *2.inner traverse the BS ...
- CLRS:max_heap and min_heap operation (pseudocode)
//max_heap heap_maximum:return A[1] O(1); Extract_Heap_maximum:swap(A[1],A[heap.size]) adjust ...
- Jmeter笔记1:使用Badboy录制脚本,作为JMeter测试的素材
接触Badboy,是因为JMeter要引用Badboy导出的脚本 Badboy的录制提供两个模式:Request(默认模式) 和navigation模式.点击下图N,切换模式:但是要导出到Jmeter ...
- storm启动分析
一个topology的启动包括了三个步骤 1)创建TopologyBuilder,设置输入源,输出源 2)获取config 3)提交topology(这里不考虑LocalCluster本地模式) 以s ...
- VS2010调试生成的文件
调试时IntelliTrace打开了,关闭IntelliTrace就可以了, Win7的话在C:\ProgramData\Microsoft Visual Studio\10.0\TraceDebug ...
- windows上修改路由表
1.查看电脑中的路由的命令: route print 2.修改“metric”,值越小权限越高: route add 0.0.0.0 mask 0.0.0.0 192.168.1.1 metric 5 ...
- view上添加点手势 button无法响应点击事件
在view 上添加手势 有的时候 会把Button的 点击事件盖掉,这个 时候 我们用UITapGestureRecognizer的代理方法 //手势的代理方法 - (BOOL)gestureRec ...
- asp.net webuploader粘贴,拖拽,点击上传图片
demo.html代码:<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset= ...