PHP SSH 连接:选择“子系统”


php ssh connection: select subsystem

我使用此库 http://phpseclib.sourceforge.net/ssh/intro.html 来创建持久的 ssh 连接。我需要选择一个子系统(这将是相应的 Unix ssh 命令中的-s参数)。

我怎样才能做到这一点?

这是我的代码

$this->ssh = new Net_SSH2($this->host, $this->port);
$key = new Crypt_RSA();
$key->loadKey(file_get_contents($this->key));
if (!$this->con->login('username', $key)) { exit('Login Failed'); }

phpseclib 的最新 git 版本应该支持这一点。

<?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('127.0.0.1');
$ssh->login('username', 'password');
$ssh->setTimeout(5);
$ssh->startSubsystem('vim');
echo $ssh->read();

这个 vim 子系统是通过在sshd_config中执行Subsystem vim /usr/bin/vim来定义的。