newgrp
命令只能在交互式shell,AFAICT中有效地使用。事实上,我放弃了......好吧,让我们先说很久,我写的替代品现在有资格在英国和美国投票。
请注意,newgrp
是'内置到'外壳的特殊命令。严格来说,它是一个shell外部的命令,但shell具有关于如何处理它的内置知识。 shell实际上是exec
的程序,所以你之后立即得到一个新的shell。它也是一个setuid根节目。在Solaris上,至少newgrp
也似乎忽略了SHELL环境变量。
我有很多方案可以解决newgrp
打算解决的问题。请记住,该命令会预先记录用户同时属于多个组的能力(请参阅Version 7 Unix Manuals)。由于newgrp
没有提供执行命令后的执行机制,与su
或sudo
不同,我编写了一个程序newgid
,与newgrp
一样,它是一个setuid根程序,允许您从一个组切换到另一个组。它非常简单 - 只需main()外加一组使用的标准化错误报告功能。与我联系(源于gmail dot com的第一个点最后)。我还有一个非常危险的命令叫'asroot
',它允许我(但只有我 - 在默认编译下)更加彻底地调整用户和组列表。
asroot: Configured for use by jleffler only
Usage: asroot [-hnpxzV] [<uid controls>] [<gid controls>] [-m umask] [--] command [arguments]
<uid controls> = [-u usr|-U uid] [-s euser|-S euid][-i user]
<gid controls> = [-C] [-g grp|-G gid] [-a grp][-A gid] [-r egrp|-R egid]
Use -h for more help
Option summary:
-a group Add auxilliary group (by name)
-A gid Add auxilliary group (by number)
-C Cancel all auxilliary groups
-g group Run with specified real GID (by name)
-G gid Run with specified real GID (by number)
-h Print this message and exit
-i Initialize UID and GIDs as if for user (by name or number)
-m umask Set umask to given value
-n Do not run program
-p Print privileges to be set
-r euser Run with specified effective UID (by name)
-R euid Run with specified effective UID (by number)
-s egroup Run with specified effective GID (by name)
-S egid Run with specified effective GID (by number)
-u user Run with specified real UID (by name)
-U uid Run with specified real UID (by number)
-V Print version and exit
-x Trace commands that are executed
-z Do not verify the UID/GID numbers
Mnemonic for effective UID/GID:
s is second letter of user;
r is second letter of group
(此程序长大:被我从头重做,我会接受用户ID或用户名,而无需不同的选项字母;对于组ID或组名同上。)
它可以是棘手获得安装setuid root程序的权限。由于多组设施,现在有一些解决方法可用。一种可行的技术是在你想要创建文件的目录上设置setgid位。这意味着无论谁创建文件,该文件都将属于拥有该目录的组。这通常可以达到你需要的效果 - 尽管我知道很少有人持续使用它。
这并不工作 – Paul 2008-11-18 19:12:27
都能跟得上...这是行不通的。 – 2008-11-18 19:30:22