Linux文件权限分为属主权限、群组权限、其他用户权限、特殊权限。特殊权限s:setUID,当用户执行具有s权限的文件时,将以所有者身份执行。eg:普通用户执行passwd修改密码时,会通过passwd的拥有者,即root执行。SetUIDchmod4xxxchmodu+sCancelSetUIDchmodxxxchmodu-ss:setGID,对于一个文件,以组权限执行。对于目录,新文件将目录的默认组作为默认组。setGIDchmod2xxxchmodg+s取消SetGIDchmodxxxchmodg-st:StickBit,stickybit,t权限的目录有wx权限。进程结束后,该文件仍驻留在内存中,其他用户无法删除。setSBITchmod1xxxchmodo+tcancelSBITchmodxxxchmodo-tshareddirectory根据setGID的特点,可以在大文件中创建和共享文件范围。先做好准备工作#创建共享组parallels@abosen:~/temp$sudogroupaddshared#将当前用户添加到共享组parallels@abosen:~/temp$sudousermod-aparallels-Gshared#新建一个userandadd进入共享组,-M不创建家目录parallels@abosen:~/temp$sudouseradd-Mperson2share-Gshared#查看结果parallels@abosen:~/temp$idperson2shareuid=1001(person2share)gid=1002(person2share)groups=1002(person2share),1001(shared)parallels@abosen:~/temp$cat/etc/group|grepsharedshared:x:1001:parallels,person2share共享目录#创建共享目录parallels@abosen:~/temp$mkdirshared_dirparallels@abosen:~/temp$ls-lFtotal4drwxrwxr-x2parallelsparallels4096Oct3115:37shared_dir/#修改目录组,设置SGIDparallels@abosen:~/temp$sudochgrpsharedshared_dir/parallels@abosen:~/temp$sudochmodg+sshared_dirparallels@abosen:~/temp$ls-lFtotal4drwxrwsr-x2parallelsshared4096Oct3115:37shared_dir/#注意组权限x变为s,设置SGID成功#新建目录文件,文件所属组为目录组,文件执行权限为组权限.可能需要设置umaskparallels@abosen:~/temp$cdshared_dir/parallels@abosen:~/temp/shared_dir$touchtestfileparallels@abosen:~/temp/shared_dir$ls-lFtotal0-rw-rw-r--1parallelsshared0Oct3115:42testfiletest#关闭所有者权限parallels@abosen:~/temp/shared_dir$sudochmodu-rwtestfile[sudo]passwordforparallels:parallels@abosen:~/temp/shared_dir$ls-lFtotal0----rw-r--1parallelsshared0Oct3115:42testfileparallels@abosen:~/temp/shared_dir$cattestfilecat:testfile:Permissiondenied#切换用户尝试parallels@abosen:~/temp/shared_dir$superson2sharePassword:$ls-lF/home/parallels/temp/shared_dir/testfile----rw-r--1parallelsshared0Oct3115:42/home/parallels/temp/shared_dir/testfile$echohello>/home/parallels/temp/shared_dir/testfile$cat/home/parallels/temp/shared_dir/testfilehello