簡單的web控制shell指令碼方法

來源:互聯網
上載者:User

標籤:web php html 可視化控制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 = false; 

        } 

    } 

</script>

<form action="restart.php" target="_blank" method="get"> 

<input name="" type="submit" value="重啟服務" onClick="checkyes()" /></form> 

</p>

</body>

</html>



3.2)

cat/var/www/html/function/restart.php


<?php

system("ssh [email protected] /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指令碼方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.