微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用phpseclib ssh2 exec()函数时如何设置标志?

我正在使用phpseclib并且需要制作一些PHP函数,这些函数可以让某人以编程方式ssh到他们的服务器并更改root密码,还可以更改可能忘记密码的用户的密码(因此必须以根).

我尝试使用libssh2,但发现它有点讨厌使用.我现在正在研究看起来更健壮的PHPseclib.但当我尝试使用’su’命令时:

echo $ssh->exec('su');

我得到了答复:

su: must be run from a terminal

当我尝试使用sudo时:

echo $ssh->exec('sudo passwd root');

我收到错误

sudo: no tty present and no askpass program specified

无论如何,事实证明su被禁用直接ssh访问,但看了this article之后,事实证明你可以使用以下命令:

ssh -t -t -l 'username' 'host' 'su -'

从我的笔记本电脑进入终端(运行ubuntu),然后我输入了我的密码,然后输入了root密码就完成了,这就是最终对我有用的东西.

从与上述链接的网站引用:

Ssh commands (using -t) the remote sshd to establish a ‘pseudo-terminal’ pipe to the worker process when -t is given.

. ssh does this as long as its stdin is a terminal.

. But if ssh’s stdin is a non-terminal, ssh won’t direct sshd to establish a
pseudo-terminal unless TWO -t’s are given:

echo password | ssh -t -t -l username remote_host

. So with -t -t (from ssh) sshd sets up a pseudo-terminal to the client process.

. The client, whether it be ‘tty’ or ‘su’ cannot tell it is connected to a ficticIoUs >terminal:

echo dummystr | ssh -t -t -l username host.com -c ”tty’

echo password | ssh -t -t -l username host.com -c ‘su -‘

So there is the answer. Use double -t if you are ‘su root’ing’ on a linux Box through an >interactive client ssh like the one from OpenBSD.

所以,它实际上是从我上面说过的终端使用:

ssh -t -t -l 'username' 'host' 'su -'

但我真的希望能够使用PHPseclib执行此命令.唯一的问题是我不知道如何将任何标志放入exec()函数中.具体来说,我需要放入-t​​标志(两次).

我找了很久,找不到任何东西.真的很感谢你的帮助.对于这篇文章的长度也很抱歉.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐