Reputation: 173
I am trying to write a php script to create users for my email server, however I am having an issue with the rights of the php intereter. The lines i am try to execute are as follows:
useradd -m -s /usr/sbin/nologin username
and then user:pass | chpasswd
.
Upvotes: 0
Views: 45
Reputation: 1249
Script on Linux is actually executed by apache itself. Apache’s user www-data
needs to be granted privileges to execute certain applications using sudo
.
There are ways to achive this,
You want to edit /etc/sudoers and using sudo visudo
this can be done.
www-data ALL=NOPASSWD: /usr/sbin/useradd, usr/bin/php
Assuming that you want to run useradd
and php
using root privileges.
Upvotes: 1
Reputation: 50787
I see this same issue come up quite frequently. Apache runs as www-data:www-data
on ubuntu. When you perform exec('useradd -m -s /usr/sbin/nologin username')
, it will execute with the same permissions as www-data
has, not as a sudoer
in the command line.
You need to adjust the permissions, fix the relationship, or offload it to a Cron Task that can
execute with the correct permissions.
Upvotes: 2