gpt4 book ai didi

ssh - Cygwin OpenSSH服务器从PHP发出第一个命令后不响应(使用phpseclib)

转载 作者:行者123 更新时间:2023-12-02 14:21:58 25 4
gpt4 key购买 nike

我的Cygwin和sshd工作正常。使用腻子根本没有问题。即使对多个命令,它也会按预期响应。但是,当使用phpseclib时,仅会收到第一个命令的响应。后续命令给出空白答复。
这是我要执行的脚本-

<?php
include('Net/SSH2.php');
define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX);
$host = "XXXX";
$username = "XXXX";
$password = "XXXX";
$ssh = new Net_SSH2($host);
if (!$ssh->login($username, $password)) {
exit('Login Failed');
}
echo $ssh->exec('nproc');
echo $ssh->exec('nproc');
echo $ssh->getLog();
?>


但是,创建新的ssh对象不会给出响应。但是,我无法将同一对象用于第二个exec请求。当目标是centos计算机时,这可以正常工作。

这是phpseclib-的日志输出
http://pastebin.com/ff3sfux7

最佳答案

我找到了解决方案-
问题的原因在于,在基于Windows的系统中,在执行新命令之前会调用setuid。对于第一个命令,其最初设置为没有问题。但是,随后的调用导致尝试重新分配它,并且失败,openssh将无法执行它。 ssh-host-config脚本中已经对此进行了解释-

*** Info: You appear to be running Windows XP 64bit, Windows 2003 Server,
*** Info: or later. On these systems, it's not possible to use the LocalSystem
*** Info: account for services that can change the user id without an
*** Info: explicit password (such as passwordless logins [e.g. public key
*** Info: authentication] via sshd).

*** Info: If you want to enable that functionality, it's required to create
*** Info: a new account with special privileges (unless a similar account
*** Info: already exists). This account is then used to run these special
*** Info: servers.

为了解决该问题,您需要创建脚本尝试创建的特权用户帐户,并确保在脚本末尾显示-
*** Info: The sshd service has been installed under the 'cyg_server'
*** Info: account. To start the service now, call `net start sshd' or
*** Info: `cygrunsrv -S sshd'. Otherwise, it will start automatically
*** Info: after the next reboot.

任何指示未找到该帐户并且默认为“SYSTEM”帐户的消息都会导致此问题。在这种情况下,请确保passwd文件是最新的,并且包括新用户。

当您启动Windows服务管理器并检查CYGWIN sshd服务的属性时,在“登录”选项卡下,需要说它正在使用新创建的特权帐户而不是本地帐户。

还要确认在组策略编辑器->安全设置->本地策略->用户权限分配下,新用户帐户需要具有创建 token 对象并作为操作系统一部分的特权。

关于ssh - Cygwin OpenSSH服务器从PHP发出第一个命令后不响应(使用phpseclib),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28250370/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com