ssh2模块无法跳转的问题? 1. LINUX 系统只能普通账号登录.2.需要su - root权限才能执行脚本。 代码无法实现,求大神解决 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <?php header("Content-type: text/html; charset=utf-8"); ?><?php$ip="127.0.0.1";$port="22";$user="root";$passwd="123";$user1="soc";$passwd1="123";if ($user1!=""){ $connection = ssh2_connect($ip,$port); if (ssh2_auth_password($connection, $user1, $passwd1)) { echo "登录成功".$ip."<br/>"; } else { echo "登录失败" . $ip . "<br/>"; exit; } if (ssh2_scp_send($connection, 'd:/tmp/Linux/36c221be-6ab2-ef53-1589-fe16877914f4.pl', '/tmp/36c221be-6ab2-ef53-1589-fe16877914f4.pl', 0777)) { echo "上传文件成功".$ip."<br/>"; } if (ssh2_scp_send($connection, 'd:/tmp/Linux/36c221be-6ab2-ef53-1589-fe16877914f4.sh', '/tmp/36c221be-6ab2-ef53-1589-fe16877914f4.sh', 0777)) { echo "上传文件成功".$ip."<br/>"; } $sushell="su - root"; $supasswd=$passwd; $conshell="sh /tmp/36c221be-6ab2-ef53-1589-fe16877914f4.sh ".$ip." ".$user." ".$passwd; if ($stream = ssh2_exec($connection,$conshell;"pwd",'xterm')) { stream_set_blocking($stream, true); if ($stream === FALSE) die("pwd failed"); echo "Output: " . stream_get_contents($stream)."<br/>"; if(ssh2_scp_recv($connection, '/tmp/'.$ip."_36c221be-6ab2-ef53-1589-fe16877914f4_chk.xml", 'd:/tmp/'.$ip."_36c221be-6ab2-ef53-1589-fe16877914f4_chk.xml")) { echo "取回成功".$ip."<br/>";} } else { echo "执行失败" . $ip; exit; }}$connection = ssh2_connect($ip,$port); if (ssh2_auth_password($connection, $user, $passwd)) { echo "登录成功".$ip."<br/>"; } else { echo "登录失败" . $ip . "<br/>"; exit; } if (ssh2_scp_send($connection, 'd:/tmp/Linux/36c221be-6ab2-ef53-1589-fe16877914f4.pl', '/tmp/36c221be-6ab2-ef53-1589-fe16877914f4.pl', 0777)) { echo "上传文件成功".$ip."<br/>"; } if (ssh2_scp_send($connection, 'd:/tmp/Linux/36c221be-6ab2-ef53-1589-fe16877914f4.sh', '/tmp/36c221be-6ab2-ef53-1589-fe16877914f4.sh', 0777)) { echo "上传文件成功".$ip."<br/>"; } if ($stream = ssh2_exec($connection, "sh /tmp/36c221be-6ab2-ef53-1589-fe16877914f4.sh ".$ip." ".$user." ".$passwd,'xterm')) { stream_set_blocking($stream, true); if ($stream === FALSE) die("pwd failed"); echo "Output: " . stream_get_contents($stream)."<br/>"; if(ssh2_scp_recv($connection, '/tmp/'.$ip."_36c221be-6ab2-ef53-1589-fe16877914f4_chk.xml", 'd:/tmp/'.$ip."_36c221be-6ab2-ef53-1589-fe16877914f4_chk.xml")) { echo "取回成功".$ip."<br/>";} }else { echo "执行失败".$ip; exit;}?> 我想实现:1. su到root(未解决)请大神帮忙解决下2.执行脚本 (已解决)3.取回结果内容(已解决) https://www.baidu.com/s?ie=UTF-8&wd=php+root 我是用 普通账号登录 意思是咋样 ssh2_exec su root 在执行操作命令呢? 用sudo请求试试,输入你自己的密码就可以。 ubuntu下eclipse不能时时显示的问题 怎么匹配出字符在文章里匹配次数最高的地方啊? 在网上没有找找到一个可以把execl文件中的 [图片] 导入数据库的方法!请教高人! 有没有办法这样子来require() 如何实现服务器内部转跳?? 一时好奇,动态改变图片上文字的php程序怎么做的?给点源代码 用户输入的值如何作为下次执行文本框的默认值呢????? 唠叨老大:总结一下吧,请求中………… 外面的变量是不是不能传到自建函数里去? extensions目录是空的?? 可变变量 可变名字 域名 配置 浏览网站空白
<?php
$ip="127.0.0.1";
$port="22";
$user="root";
$passwd="123";
$user1="soc";
$passwd1="123";if ($user1!="")
{ $connection = ssh2_connect($ip,$port);
if (ssh2_auth_password($connection, $user1, $passwd1))
{
echo "登录成功".$ip."<br/>"; }
else {
echo "登录失败" . $ip . "<br/>";
exit;
} if (ssh2_scp_send($connection, 'd:/tmp/Linux/36c221be-6ab2-ef53-1589-fe16877914f4.pl', '/tmp/36c221be-6ab2-ef53-1589-fe16877914f4.pl', 0777))
{ echo "上传文件成功".$ip."<br/>";
}
if (ssh2_scp_send($connection, 'd:/tmp/Linux/36c221be-6ab2-ef53-1589-fe16877914f4.sh', '/tmp/36c221be-6ab2-ef53-1589-fe16877914f4.sh', 0777))
{ echo "上传文件成功".$ip."<br/>";
}
$sushell="su - root";
$supasswd=$passwd;
$conshell="sh /tmp/36c221be-6ab2-ef53-1589-fe16877914f4.sh ".$ip." ".$user." ".$passwd;
if ($stream = ssh2_exec($connection,$conshell;"pwd",'xterm'))
{
stream_set_blocking($stream, true);
if ($stream === FALSE) die("pwd failed");
echo "Output: " . stream_get_contents($stream)."<br/>";
if(ssh2_scp_recv($connection, '/tmp/'.$ip."_36c221be-6ab2-ef53-1589-fe16877914f4_chk.xml", 'd:/tmp/'.$ip."_36c221be-6ab2-ef53-1589-fe16877914f4_chk.xml"))
{ echo "取回成功".$ip."<br/>";} }
else {
echo "执行失败" . $ip;
exit; }
}$connection = ssh2_connect($ip,$port);
if (ssh2_auth_password($connection, $user, $passwd))
{
echo "登录成功".$ip."<br/>"; }
else {
echo "登录失败" . $ip . "<br/>";
exit;
} if (ssh2_scp_send($connection, 'd:/tmp/Linux/36c221be-6ab2-ef53-1589-fe16877914f4.pl', '/tmp/36c221be-6ab2-ef53-1589-fe16877914f4.pl', 0777))
{ echo "上传文件成功".$ip."<br/>";
}
if (ssh2_scp_send($connection, 'd:/tmp/Linux/36c221be-6ab2-ef53-1589-fe16877914f4.sh', '/tmp/36c221be-6ab2-ef53-1589-fe16877914f4.sh', 0777))
{ echo "上传文件成功".$ip."<br/>";
} if ($stream = ssh2_exec($connection, "sh /tmp/36c221be-6ab2-ef53-1589-fe16877914f4.sh ".$ip." ".$user." ".$passwd,'xterm'))
{
stream_set_blocking($stream, true);
if ($stream === FALSE) die("pwd failed");
echo "Output: " . stream_get_contents($stream)."<br/>";
if(ssh2_scp_recv($connection, '/tmp/'.$ip."_36c221be-6ab2-ef53-1589-fe16877914f4_chk.xml", 'd:/tmp/'.$ip."_36c221be-6ab2-ef53-1589-fe16877914f4_chk.xml"))
{ echo "取回成功".$ip."<br/>";} }
else {
echo "执行失败".$ip;
exit;
}
?>
1. su到root(未解决)请大神帮忙解决下2.执行脚本 (已解决)
3.取回结果内容(已解决)
我是用 普通账号登录 意思是咋样 ssh2_exec su root 在执行操作命令呢?