简单的web控制shell脚本方法

发布时间:2020-06-28 10:17:20 作者:leonardos
来源:网络 阅读:1285

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>

推荐阅读:
  1. shell脚本的简单制作与格式
  2. 简单的独立按键控制继电器

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

php html web

上一篇:OC的内存管理

下一篇:R语言实现固定分组汇总的方法

相关阅读

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

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