首页 > 代码库 > 简单的web控制shell脚本方法
简单的web控制shell脚本方法
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
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>重启服务</title>
</head>
<body>
<p>
<script language="javascript">
function checkyes() {
if (!confirm("确认要重启?")) {
window.event.returnValue = http://www.mamicode.com/false;
}
}
</script>
<form action="restart.php" target="_blank" method="get">
<input name="" type="submit" value="http://www.mamicode.com/重启服务" onClick="checkyes()" /></form>
</p>
</body>
</html>
3.2)
cat/var/www/html/function/restart.php
<?php
system("ssh root@x.x.x.x /root/scripts/test.sh");
?>
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>
简单的web控制shell脚本方法