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条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大