php頁面遠程執行shell指令碼

來源:互聯網
上載者:User

php在執行shell時使用的預設使用者為nobody使用者,因此引起命令無法執行返回結果為空白的問題。

既然是許可權問題,那麼可以轉換成root來執行,sudo即可

轉換為root或者相應的使用者來執行命令

exec('sudo -u root -S your_command');

遠程,當然得加上伺服器本身的key,這樣方便

需要的配置:

a. 配置nobody使用者的sudo許可權,修改/etc/sudoers

chmod u+x /etc/sudoers

在root    ALL=(ALL)   ALL 下添加 nobody  ALL=(ALL)   ALL

www則是:www     ALL=(ALL)       NOPASSWD:ALL

chmod u-x /etc/sudoers

b. 修改sudoer預設需要tty的配置

在/etc/sudoers中注釋掉Defaults    requiretty

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.