無法使用php腳本變更linux使用者密碼

無法使用php腳本變更linux使用者密碼

我有以下用於更改密碼的 php 腳本: <?php error_reporting(E_ALL); ini_set('顯示錯誤', TRUE); ini_set('display_startup_errors', TRUE); ini_set('display_error', true);

$cmd = 'sudo -u root sh -c \'/usr/bin/echo "username:pass" | sudo /usr/sbin/chpasswd 2>&1\'';
exec($cmd,$output,$return_val);
print_r($output);
echo $return_val;
?>

該腳本在瀏覽器中顯示錯誤:

pam_chauthtok() failed, error: [1] => Authentication token lock busy [2] => chpasswd

但命令

sudo -u root sh -c '/usr/bin/echo "username:pass" | sudo /usr/sbin/chpasswd 2>&1'

工作正常。請有人給我提示,為什麼我在瀏覽器中出現上述錯誤?

檔案系統處於 rw 模式。檔案 /etc/{passwd,shadow} 具有正確的權限

先感謝您

答案1

ProtectSystem=full解決辦法是在 php-fpm.service 單元中註解掉:

# Mounts the /usr, /boot, and /etc directories read-only for processes invoked by this unit.
#ProtectSystem=full

答案2

www-data瀏覽器php使用使用者運行

使用命令新增透過 shellwww-data使用的權限並附加此行sudovisudo

www-data   ALL=(ALL:ALL) ALL

它的語法是

user    hosts=(users:groups)    commands

相關內容