I have a script that is executed by php so it runs as the www-data user. The script is pretty simple, it basically copies some pre-made files such as the hosts and interfaces files to the correct directories. Maybe update some permissions etc.
I thought creating a new user and giving that access to the required commands only through
visudo might work but
- that still requests the user executing the
.shfor a password and
- it plainly does not give the test user permissions.
visudo (all permission denied when running
test ALL=(ALL) NOPASSWD:ALL test ALL= NOPASSWD:ALL test ALL=(ALL) NOPASSWD:/bin/cp,/bin/mv,/bin/nano,/bin/chown,/bin/mv
When I change the
test user to the actual user I'm logged in with, it works.
.sh executed by the logged in/
www-data user trying to execute the commands as a different user with the required permissions.
#!/bin/bash sudo -H -u test cp test.txt /etc/test.txt sudo -H -u test chown test /etc/test.txt echo "ok"
What is the best way to enable the
www-data user to execute a script that requires