T
T
Twelfth Doctor2017-07-24 16:44:10
linux
Twelfth Doctor, 2017-07-24 16:44:10

Why is the system user not being created?

Hello! Prompt, why the system user can not be created?
Here is the function

protected function create(array $data)
    {
//создаем пользователя в базе данных
        $user= User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
            'role'=>'customer',
        ]);

//получаем его ID
        $id = $user->id;
        $pass = $data['password'];
//создаем пользователя в Linux
        shell_exec("useradd -d /home/u$id/ u$id");
        shell_exec("echo u$id:$pass | chpasswd");
//возвратить экземпляр класса User
      return $user;
    }

The problem is that for some reason the user of the Linux system is not created. For the user who runs the web application in /etc/sudoers wrote:
user ALL=(ALL) NOPASSWD:ALL
(unfortunately I don’t know how to give access only to individual commands).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nazar Mokrinsky, 2017-07-24
@verdex

shell_exec returns the output of the running command as the result of the function.
To begin with, do var_dump(shell_exec())and see what's the matter, what the team swears at (if it swears).
In general, I would recommend exec()checking the status code of the result of the command, because the second command does not need to be executed if the first one fails with an error.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question