三种进程用户的简单解释:
三种用户/组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的关系的更多相关文章

  1. 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 ...

  2. UID, EUID, SUID, FSUID

    摘自:https://blog.csdn.net/wh8_2011/article/details/50825340 UID, EUID, SUID, FSUID 2016年03月08日 10:40: ...

  3. [代码修订版] Python 踩坑之旅 [进程篇其四] 踩透 uid euid suid gid egid sgid的坑坑洼洼

    目录 1.1 踩坑案例 1.2 填坑解法 1.3 坑位分析 1.4 技术关键字 1.5 坑后思考 下期坑位预告 代码示例支持 平台: Centos 6.3 Python: 2.7.14 代码示例: 公 ...

  4. Python 踩坑之旅进程篇其四一次性踩透 uid euid suid gid egid sgid的坑坑洼洼

    目录 1.1 踩坑案例 1.2 填坑解法 1.3 坑位分析 1.4 技术关键字 1.5 坑后思考 下期坑位预告 代码示例支持 平台: Centos 6.3 Python: 2.7.14 代码示例: 菜 ...

  5. 整理下本周工作中遇到的疑问;uid/euid/suid;docker镜像管理

    1.系统中的父子进程关系,以及docker是如何处理的这种父子进程关系,线上问题发现,子进程长时间得不到退出. 2.调用system系统调用发生了啥事情,发现大量的页表拷贝. 3.通过shell命令通 ...

  6. linux UID,GID,EUID,EGID,SUID,SGID

    SUID, SGID, sticky位可以参考: http://onlyzq.blog.51cto.com/1228/527247/ SUID属性只能运用在可执行文件上,当用户执行该执行文件时,会临时 ...

  7. Linux 特殊权限 SUID,SGID,SBIT

    setuid 和 setgid 分别是 set uid ID upon execution 和 set group ID upon execution 的缩写.我们一般会再次把它们缩写为 suid 和 ...

  8. linux特殊权限SUID、SGID、SBIT

    对于linux中文件或目录的权限,应该都知道普通的rwx权限(关于linux中rwx权限的看我的这篇博文http://www.cnblogs.com/javaee6/p/3994750.html).我 ...

  9. Linux特殊位SUID、SGID、SBIT

    Linux特殊位SUID.SGID.SBIT 前言 Linux中的文件权限一般有x.w.r,在某个情况下有需要用到s.t,即特殊位. 进程运行时能够访问哪些资源或文件,不取决于进程文件的属主属组,而是 ...

随机推荐

  1. MSP430F149学习之路——比较器Comparaor_A

    代码一: #include <msp430x14x.h> ; void int_clk() { BCSCTL1 &= ~XT2OFF; BCSCTL2 |= SELM_2 + SE ...

  2. ubuntu下,apt的参数使用,很实用呦

    ubuntu下apt-get 命令参数 常用的APT命令参数 apt-cache search package 搜索包 apt-cache show package 获取包的相关信息,如说明.大小.版 ...

  3. tcp timestamp

    Description Protocol suite: TCP/IP. Protocol type: Transport layer protocol. Option length: 10 bytes ...

  4. poj1019_Number_Sequence

    这题目关键是打表,haha[k]数组表示的是S1S2..Sk该串结尾所在的位置.然后用n去找n所在的k值,此时haha[k-1]<n<=haha[k].然后再算出从haha[k]位置到n一 ...

  5. JS回车事件

    <script type="text/javascript"> //当回车按下时,/=47,*=42,+=43 function keypress(form0){ if ...

  6. Git 中级用户的25个提示

    我使用 Git 大约已经有18个月时间,自认为能很好地驾驭它了.但是当我们请到 GitHub 的 Scott Chacon 来到 LVS 公司(一个博彩/游戏软件供应商/开发商)做专场培训时,我在第一 ...

  7. svn服务器搭建与配置

    http://www.cnblogs.com/armyfai/p/3985660.html

  8. 在mac系统上安装Eclipse,编写java程序

    第一步:安装java jre(java 运行环境). 如图所示: 登陆Oralce官网,点击Download选项,找到如图所示界面: 选择Java Runtime Environment(JRE),打 ...

  9. Qt使用默认浏览器打开网页

    #include <QDesktopServices> #include <QUrl> QDesktopServices::openUrl(QUrl("http:// ...

  10. 复习URLHttpConnection方式GET,POST方式链接网络解析uri

    xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:t ...