dt4233 2009-10-20 09:25
浏览 70
已采纳

用于创建用户passwd的命令行脚本

I'm very new to Linux and PHP so forgive me if this is a dumb question.

I need to create a PHP command line script that will add a user to the system, to be used by the ftp server. I have it set up at this point that it creates the account just fine. The problem I'm facing is that even though I pass through the password when I create the account ie. -p $password, I still have to run the "passwd" command on the account and set the password manually before proftpd will let that account log in.

For the life of me I can't figure out how to run the passwd command from within the php. Obviously I can run it, but I have no idea how to programatically enter the password when prompted.

Just for more info, this is the command I run when creating the account. $username and $ password are passed into the function.

shell_exec("useradd ".$username." -g ftpusers -m -p ".$password." -d
/home/ftp/".$username."/ -s /bin/false);

now im looking to add something along the lines of:

shell_exec("passwd ".$username);
echo $password;
echo $password;

Just for the record, this last example is just for illustration.

Any help appreciated.

  • 写回答

3条回答 默认 最新

  • douhui9192 2009-10-20 09:35
    关注

    You need to use the hashed password using useradd, e.g.

    $password = escapeshellarg( crypt('password') );
    shell_exec("useradd username -p $password");
    

    -p, --password PASSWORD The encrypted password, as returned by crypt(3). The default is to disable the account.

    (man useradd)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?