您好,登录后才能下订单哦!
1)查看php运行用户:
<?php
system('id -a');
?>
一般php运行用户是apache
2)给apache用户做密钥信任:
2.1)
先看看apache用户的信息:
# su - apache
This account is currently not available.
# cat /etc/passwd|grep apache
apache:x:48:48:Apache:/var/www:/sbin/nologin
改为:
apache:x:48:48:Apache:/var/www:/bin/bash
2.2)
root用户上操作:
mkdir /var/www/.ssh
chown apache. /var/www/.ssh
2.3)
然后再切换到apache用户:
su - apache
ssh-keygen -t rsa
2.4)
root用户上操作,最后改回nologin:
apache:x:48:48:Apache:/var/www:/sbin/nologin
3)页面写法:
3.1)
cat /var/www/html/function/restart.html
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>重启服务</title>
</head>
<body>
<a href="javascript:if(confirm('确定要重启吗?'))location='restart.php'">重启</a>
</body>
</html>
3.2)
cat/var/www/html/function/restart.php
<?php
system("ssh root@x.x.x.x /root/scripts/test.sh",$returnvalue);
if ($returnvalue == 0){
echo('<hr/><font color=green size=3><B>重启成功</B></font><br/>');
}
else{
echo('<hr/><font color=red size=3><B>重启失败</B></font><br/>');
}
?>
3.3)
apache配置里加密码验证:
<Directory /var/www/html/function/>
AuthType Basic
AuthName sys
AuthUserFile /var/www/html/function/.htpasswd
require user sys
</Directory>
htpasswd -bc /var/www/html/function/.htpasswd sys 123456
3.4)
做个超链接嵌入其他页面
<a href="http://x.x.x.x/function/restart.html" target="_blank">重启</a>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。