ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

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

2019-09-03 11:32:48  阅读:358  来源: 互联网

标签:php ssh phpseclib


我正在使用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​​标志(两次).

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

标签:php,ssh,phpseclib
来源: https://codeday.me/bug/20190903/1797751.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有