"su <otheruser>" 失败 "standard in must be atty"
"su <otheruser>" fails with "standard in must be atty"
我研究了这个问题,所有答案都建议 visudo 添加:
Defaults:user !requiretty
没用!
我有两个 Linux 盒子 (RedHat)。我有一个 Java class ,它使用 ProcessBuilder/Process 来执行命令。系统帐号下的class 运行s。
在两个盒子上,我 运行
su other-user -c 'some-command'
并在 Process 对象的输入流中为其他用户提供密码。
在一个盒子上,命令成功,而在另一个盒子上我得到上面的错误。
两台机器上的 sudoers 文件都没有排除 requiretty('Defaults requiretty' 设置在两个文件上)。
我尝试按照我找到的答案的建议添加排除项。我尝试了系统用户 运行ning 进程和 'other-user'...
无效。
还有什么问题?添加要求异常后是否需要重启系统?
sudoers
用于 sudo
而不是 su
所以你应该使用 sudo
.
根据 su
手册:
-c, --command COMMAND
Specify a command that will be invoked by the shell using its -c
.
The executed command will have no controlling terminal. This option cannot be used to execute interactive programs which need a controlling TTY.
如果您试图避免使用 sudo 或您没有 sudo 权限,则可以使用 TTY 生成。
只需在 运行 给出您提到的错误的代码之前调用以下代码之一。
这里有一些您可以使用的代码示例,具体取决于您使用的代码或系统:
python -c 'import pty; pty.spawn("/bin/sh")'
echo os.system('/bin/bash')
/bin/sh -i
perl —e 'exec "/bin/sh";'
perl: exec "/bin/sh";
ruby: exec "/bin/sh"
lua: os.execute('/bin/sh')
(来自IRB内部)
exec "/bin/sh"
(来自 vi)
:!bash
(来自 vi)
:set shell=/bin/bash:shell
(来自nmap内部)
!sh
前三个选项是我常用的,我相信他们的结果。
我在渗透测试时使用它们。
我研究了这个问题,所有答案都建议 visudo 添加: Defaults:user !requiretty
没用!
我有两个 Linux 盒子 (RedHat)。我有一个 Java class ,它使用 ProcessBuilder/Process 来执行命令。系统帐号下的class 运行s。 在两个盒子上,我 运行
su other-user -c 'some-command'
并在 Process 对象的输入流中为其他用户提供密码。
在一个盒子上,命令成功,而在另一个盒子上我得到上面的错误。 两台机器上的 sudoers 文件都没有排除 requiretty('Defaults requiretty' 设置在两个文件上)。 我尝试按照我找到的答案的建议添加排除项。我尝试了系统用户 运行ning 进程和 'other-user'...
无效。
还有什么问题?添加要求异常后是否需要重启系统?
sudoers
用于 sudo
而不是 su
所以你应该使用 sudo
.
根据 su
手册:
-c, --command COMMAND
Specify a command that will be invoked by the shell using its
-c
.The executed command will have no controlling terminal. This option cannot be used to execute interactive programs which need a controlling TTY.
如果您试图避免使用 sudo 或您没有 sudo 权限,则可以使用 TTY 生成。
只需在 运行 给出您提到的错误的代码之前调用以下代码之一。
这里有一些您可以使用的代码示例,具体取决于您使用的代码或系统:
python -c 'import pty; pty.spawn("/bin/sh")'
echo os.system('/bin/bash')
/bin/sh -i
perl —e 'exec "/bin/sh";'
perl: exec "/bin/sh";
ruby: exec "/bin/sh"
lua: os.execute('/bin/sh')
(来自IRB内部)
exec "/bin/sh"
(来自 vi)
:!bash
(来自 vi)
:set shell=/bin/bash:shell
(来自nmap内部)
!sh
前三个选项是我常用的,我相信他们的结果。 我在渗透测试时使用它们。