给 ftp 用户一个随机密码
giving ftp user a random password
所以我正在尝试创建一个新的 ftp 用户和目录,并只给他该目录的权限。但问题是为创建的用户设置密码时。它创建了用户,但是当我尝试为他设置密码时我得到了这个
Creating home directory /home/kwgazl69' ... Copying files from
/etc/skel' ... Enter new UNIX password: passwd: user 'test123' does not exist
我做错了什么?这是代码
$src = $request->path;
$dest = "/home/$randomNum/serverFiles";
echo $ssh->exec("adduser --force-badname $randomNum");
echo $ssh->exec("passwd test123");
echo $ssh->exec("cp -r $src $dest");
echo $ssh->exec("usermod -d $dest $randomNum");
echo $ssh->exec("cd $dest && ./samp03svr");
$ssh->disconnect();
Adding user ln2i78yt' ... Adding new group
ln2i78yt' (1010) ... Adding new user ln2i78yt' (1010) with group
ln2i78yt' ... Creating home directory /home/ln2i78yt' ... Copying files from
/etc/skel' ... Enter new UNIX password: passwd: unrecognized option '--stdin' Usage: passwd [options] [LOGIN] Options: -a, --all report password status on all accounts -d, --delete delete the password for the named account -e, --expire force expire the password for the named account -h, --help display this help message and exit -k, --keep-tokens change password only if expired -i, --inactive INACTIVE set password inactive after expiration to INACTIVE -l, --lock lock the password of the named account -n, --mindays MIN_DAYS set minimum number of days before password change to MIN_DAYS -q, --quiet quiet mode -r, --repository REPOSITORY change password in REPOSITORY repository -R, --root CHROOT_DIR directory to chroot into -S, --status report password status on the named account -u, --unlock unlock the password of the named account -w, --warndays WARN_DAYS set expiration warning days to WARN_DAYS -x, --maxdays MAX_DAYS set maximum number of days before password change to MAX_DAYS
您实际上是在尝试更改用户 'test123' 的密码,而不是将密码设置为 'test123'。
您需要将密码传递到标准输入,所以这样做:
echo $ssh->exec('echo -e "test123\ntest123" | passwd ' . $randomNum);
passwd
期望第一个参数是用户名,然后它要求输入密码两次。您可以尝试使用另一个名为 chpasswd
的命令。它需要用冒号分隔的用户名和密码。
$src = $request->path;
$dest = "/home/$randomNum/serverFiles";
echo $ssh->exec("adduser --force-badname $randomNum");
echo $ssh->exec("echo \"$randomNum:test123\" | chpasswd");
echo $ssh->exec("cp -r $src $dest");
echo $ssh->exec("usermod -d $dest $randomNum");
echo $ssh->exec("cd $dest && ./samp03svr");
$ssh->disconnect();
所以我正在尝试创建一个新的 ftp 用户和目录,并只给他该目录的权限。但问题是为创建的用户设置密码时。它创建了用户,但是当我尝试为他设置密码时我得到了这个
Creating home directory
/home/kwgazl69' ... Copying files from
/etc/skel' ... Enter new UNIX password: passwd: user 'test123' does not exist
我做错了什么?这是代码
$src = $request->path;
$dest = "/home/$randomNum/serverFiles";
echo $ssh->exec("adduser --force-badname $randomNum");
echo $ssh->exec("passwd test123");
echo $ssh->exec("cp -r $src $dest");
echo $ssh->exec("usermod -d $dest $randomNum");
echo $ssh->exec("cd $dest && ./samp03svr");
$ssh->disconnect();
Adding user
ln2i78yt' ... Adding new group
ln2i78yt' (1010) ... Adding new userln2i78yt' (1010) with group
ln2i78yt' ... Creating home directory/home/ln2i78yt' ... Copying files from
/etc/skel' ... Enter new UNIX password: passwd: unrecognized option '--stdin' Usage: passwd [options] [LOGIN] Options: -a, --all report password status on all accounts -d, --delete delete the password for the named account -e, --expire force expire the password for the named account -h, --help display this help message and exit -k, --keep-tokens change password only if expired -i, --inactive INACTIVE set password inactive after expiration to INACTIVE -l, --lock lock the password of the named account -n, --mindays MIN_DAYS set minimum number of days before password change to MIN_DAYS -q, --quiet quiet mode -r, --repository REPOSITORY change password in REPOSITORY repository -R, --root CHROOT_DIR directory to chroot into -S, --status report password status on the named account -u, --unlock unlock the password of the named account -w, --warndays WARN_DAYS set expiration warning days to WARN_DAYS -x, --maxdays MAX_DAYS set maximum number of days before password change to MAX_DAYS
您实际上是在尝试更改用户 'test123' 的密码,而不是将密码设置为 'test123'。
您需要将密码传递到标准输入,所以这样做:
echo $ssh->exec('echo -e "test123\ntest123" | passwd ' . $randomNum);
passwd
期望第一个参数是用户名,然后它要求输入密码两次。您可以尝试使用另一个名为 chpasswd
的命令。它需要用冒号分隔的用户名和密码。
$src = $request->path;
$dest = "/home/$randomNum/serverFiles";
echo $ssh->exec("adduser --force-badname $randomNum");
echo $ssh->exec("echo \"$randomNum:test123\" | chpasswd");
echo $ssh->exec("cp -r $src $dest");
echo $ssh->exec("usermod -d $dest $randomNum");
echo $ssh->exec("cd $dest && ./samp03svr");
$ssh->disconnect();