使用phpseclib和net_ssh如何使用$ssh-> exec su到root
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了使用phpseclib和net_ssh如何使用$ssh-> exec su到root,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3192字,纯文字阅读大概需要5分钟。
内容图文
所以我需要执行一个命令但它只会运行,如果我su到root(或sudo)但我似乎无法弄清楚如何将命令发送到su到root
(我可以使用loginuser登录并执行其他命令)
http://phpseclib.sourceforge.net/ssh/examples.html
我的代码如下
<?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('255.255.255.255',22);
if (!$ssh->login('loginuser', 'fakepassword')) {
exit('Login Failed');
}
echo $ssh->read('[prompt]');
echo $ssh->write("su\n");
echo $ssh->read('Password:');
echo $ssh->write("rootfakepassword");
echo $ssh->read('[prompt]');
echo $ssh->exec('cc get_wireless_status');
?>
我也尝试使用exec命令做大致相同的事情而没有运气
有什么建议?
当前版本的代码(不起作用)
<?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('255.255.99.74',22);
if (!$ssh->login('loginuser', 'password')) {
exit('Login Failed');
}
echo $ssh->read('loginuser@intranet:/home/login >');
$ssh->write("su\n");
echo $ssh->read('Password:');
$ssh->write("rootpassword\n");
echo $ssh->read('intranet:/home/login #');
$ssh->write("cc get_wireless_status\n");
echo $ssh->read('[prompt]');
?>
腻子文本的登录
login as: loginuser
loginuser@255.255.99.74's password:
Last login: Thu Feb 14 13:57:16 2013 from infong1045.lxa.perfora.net
Sophos UTM
(C) Copyrights by Astaro and by others 2000-2012.
For more copyright information look at /doc/astaro-license.txt
or http://www.astaro.com/doc/astaro-license.txt
NOTE: Any modifications done by root will void your support.
Please use WebAdmin for any configuration changes.
loginuser@intranet:/home/login > su
Password:
intranet:/home/login #
来自最新版本的代码的响应
Last login: Thu Feb 14 14:00:00 2013 from 10.10.10.194 Sophos UTM (C) Copyrights by Astaro and by others 2000-2012. For more copyright information look at /doc/astaro-license.txt or http://www.astaro.com/doc/astaro-license.txt NOTE: Any modifications done by root will void your support. Please use WebAdmin for any configuration changes. loginuser@intranet:/home/login > Last login: Tue Feb 19 11:09:18 2013 from infong1045.lxa.perfora.net Sophos UTM (C) Copyrights by Astaro and by others 2000-2012. For more copyright information look at /doc/astaro-license.txt or http://www.astaro.com/doc/astaro-license.txt NOTE: Any modifications done by root will void your support. Please use WebAdmin for any configuration changes. loginuser@intranet:/home/login > su Password: intranet:/home/login # Last login: Tue Feb 19 11:09:23 2013 from infong1045.lxa.perfora.net Sophos UTM (C) Copyrights by Astaro and by others 2000-2012. For more copyright information look at /doc/astaro-license.txt or http://www.astaro.com/doc/astaro-license.txt NOTE: Any modifications done by root will void your support. Please use WebAdmin for any configuration changes. loginuser@intranet:/home/login > cc get_wireless_status -bash: /usr/local/bin/confd-client.plx: Permission denied loginuser@intranet:/home/login >
解决方法:
这应该工作:
<?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', 'password')) {
exit('Login Failed');
}
echo $ssh->read('username@username:~$');
$ssh->write("su\n");
echo $ssh->read('Password:');
$ssh->write("password\n");
echo $ssh->read('username@username:~#');
$ssh->write("cc get_wireless_status\n");
echo $ssh->read('[prompt]');
?>
内容总结
以上是互联网集市为您收集整理的使用phpseclib和net_ssh如何使用$ssh-> exec su到root全部内容,希望文章能够帮你解决使用phpseclib和net_ssh如何使用$ssh-> exec su到root所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。