我在Lubuntu 16.04上使用Bash。 LTS,但我不确定这对这个问题是否重要。sudo -u有缺陷的文件权限
我注意到,当我以标准用户创建文件时,该文件具有664个权限。但是,当我是root用户并通过-u参数为同一用户执行相同的命令时,它具有644个权限,因此组的写入权限丢失。
我想这是一大败笔,因为sudo
联机手册明确规定:
-u user, --user=user
Run the command as a user other than the default target user (usually root). The user may be either a user name or a
numeric user ID (UID) prefixed with the ‘#’ character (e.g. #0 for UID 0). When running commands as a UID, many
shells require that the ‘#’ be escaped with a backslash (‘\’). Some security policies may restrict UIDs to those
listed in the password database. The sudoers policy allows UIDs that are not in the password database as long as the
targetpw option is not set. Other security policies may not support this.
现在我知道-u
参数的行为从具有可预期的行为不同,我的问题是:
如何确保在根shell中启动的命令执行刚好是,因为它将从其他用户的shell执行?
备注:我知道我可以通过修补umask
来解决这个问题,但这并不能保证我的行为在任意数量的其他情况下没有差异。
”的执行完全按照它从另一个我们执行的那样执行呃的外壳?“ - 执行该用户的shell。例如“'sudo -u用户sh -c'一些命令''”。请注意,每个用户都指定他们自己的shell。 'getent passwd user'获取详细信息 –
有趣的是,这不起作用 - 文件许可仍然是644 – Wanderer
Stack Overflow是一个编程和开发问题的网站。这个问题似乎与题目无关,因为它不涉及编程或开发。请参阅帮助中心的[我可以询问哪些主题](http://stackoverflow.com/help/on-topic)。也许[超级用户](http://superuser.com/)或[Unix&Linux堆栈交换](http://unix.stackexchange.com/)会是一个更好的地方。 – jww