温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

简单的web控制shell脚本方法

发布时间:2020-06-28 10:17:20 阅读:1312 作者:leonardos 栏目:web开发
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

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>

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI

开发者交流群×