%3B%60.png)
當我運行腳本時<?php chdir('/var/www/html'); echo shell_exec('git pull origin master 2>&1'); ?>
,我收到錯誤訊息:
error: cannot open .git/FETCH_HEAD: Permission denied
這就是我所做的:
ssh [email protected]
pwd # shows that I'm already at /var/www as my home directory
ls .ssh/ # shows that I have id_rsa and id_rsa.pub, and id_rsa.pub is given to github
cd html
git pull origin master # everything downloads perfectly
echo "<?php chdir('/var/www/html'); echo shell_exec('git pull origin master 2>&1'); " > pull.php
現在,當我去時,http://example.com/pull.php
我收到錯誤cannot open .git/FETCH_HEAD: Permission denied
。
為了確認我的權限,我以 root 身分登入來執行chown -R apache:apache /var/www
.我的裡面也有這個/etc/passwd
apache:x:48:48:Apache:/var/www:/bin/bash
我究竟做錯了什麼?
答案1
SELinux 不允許 Web 伺服器寫入隨機目錄。您需要透過設定預設上下文httpd_sys_rw_content_t
然後設定任何現有檔案的上下文來明確定義 SELinux 應該允許哪些目錄可寫入。例如:
semanage fcontext -a -t httpd_sys_rw_content_t "/var/www(/.*)?"
restorecon -rv /var/www
但幾乎可以肯定,您不應該使整個網站可由 Web 伺服器寫入,也不應該設定直接呼叫git
.這兩者都完全否定了您可以從 SELinux 獲得的任何安全優勢,而且後者也有其自身的一系列潛在問題。