-1

i have a working bash script wich makes a new user on my server.

#!/usr/bin/env bash

if [[ $# -eq 0 ]] ; then
    

    exit 0
fi


username=${1?Error: no name given}
password=${2?Error: no password given}


echo "* Adding new user $username"
useradd -s /bin/bash -m -d /home/$username $username


echo "$username:$password" | chpasswd
echo "* Password set for user $username" 

i want a php page wich runs this code and makes a user on the server.

<?php

$username = $_POST['uname'];
$password = $_POST['psw'];

echo "$username";
echo "$password";

$output = exec("sudo ./createuser.sh $username $password");
echo "$output";

?>

but when i run the php page noting happens no user is added. How can i fix this

  • 1
    You try to execute a sudo command from your PHP code which is probably not running as root. This is not allowed. See https://stackoverflow.com/questions/3173201/sudo-in-php-exec. – Pierre François May 27 '21 at 20:25

1 Answers1

-1

Remove sudo and grant execution privileges to the script:

$ sudo chmod +x /path/to/createuser.sh

And try again

rafarods
  • 18
  • 5