
Tengo el siguiente script php para cambiar la contraseña: <?php error_reporting(E_ALL); ini_set('display_errors', VERDADERO); ini_set('display_startup_errors', VERDADERO); ini_set('display_error', verdadero);
$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;
?>
Este script muestra un error en el navegador:
pam_chauthtok() failed, error: [1] => Authentication token lock busy [2] => chpasswd
Pero el comando
sudo -u root sh -c '/usr/bin/echo "username:pass" | sudo /usr/sbin/chpasswd 2>&1'
trabaja bien. ¿Puede alguien darme un consejo sobre por qué aparece el error anterior en el navegador?
El sistema de archivos está en modo rw. Los archivos /etc/{passwd,shadow} tienen los permisos correctos
gracias de antemano
Respuesta1
La solución fue comentar ProtectSystem=full
en la unidad php-fpm.service:
# Mounts the /usr, /boot, and /etc directories read-only for processes invoked by this unit.
#ProtectSystem=full
Respuesta2
El navegador php se ejecuta usando www-data
el usuario
Agregue permisos para www-data
usarlos sudo
a través del shell usando visudo
el comando y agregue esta línea
www-data ALL=(ALL:ALL) ALL
Su sintaxis es
user hosts=(users:groups) commands