I am required to create a new user and then svn co into the newly created user's home directory by calling a bash script from a php page.
The below example is a line from the sudoers file which I saw at some other forum.
http ALL=NOPASSWD:/usr/sbin/useradd,/bin/mkdir,/bin/ln,/bin/chown,/bin/cp,/bin/sed
This line obviously sets a passwordless sudo for the user http and adds privileges to the user http to use useradd, mkdir, chown, cp and sedcommands. I would not like to disable the sudo prompt for all users but just for the newly created user (I had seen an answer regarding commenting a certain line in the sudoers file for preventing the sudo password prompt here at AU).
Similarly I would like to add svn privileges onto the www-data user.
www-data ALL=NOPASSWD: /usr/sbin/useradd,/bin/svn
Currently the www-data user is able to create a new user using the useradd command, but is unable to use the svn command. ( I may be doing it completely wrong so feel free to correct me)
This is the bash script that I am trying to run.
sudo useradd newuser -d /home/newuser -s /bin/bash -m -p password
echo yes | sudo svn --username [username] --password [password] co [SVN link] /home/newuser/public_html
When I try to call this script from the php page using the command
$output = shell_exec("sh ./includes/setupsite.sh 2>&1");
I get the error
sudo: no tty present and no askpass program specified for the second line (the svn co line)
But instead when I try to run without sudo I get
----------------------------------------------------------------------- ATTENTION! Your password for authentication realm: Authentication Required can only be stored to disk unencrypted! You are advised to configure your system so that Subversion can store passwords encrypted, if possible. See the documentation for details. You can avoid future appearances of this warning by setting the value of the 'store-plaintext-passwords' option to either 'yes' or 'no' in '/var/www/.subversion/servers'. ----------------------------------------------------------------------- Store password unencrypted (yes/no)? svn: Can't make directory '/home/newuser/public_html': Permission denied
So that made it obvious that sudo might be required. I saw a similar question here itself. But that was not answered and the answer provided didn't solve my issue.
Update: The file permissions/ownership are:
-rwxrwxrwx 1 www-data www-data 326 2012-08-08 17:56 setupsite.sh
If you need any clarifications please leave a comment and I'll edit my question to add those details (provided that I have them) ASAP.