当我们需要用命令代替我们往Linux窗口输入东西时,可以考虑使用Linux文件描述符里的标准输入,而passwd、smbpasswd命令均有自己对应的标准输入参数,我们可以通过查看它们的帮助信息获取相应参数。
passwd=**** && (echo $passwd;echo $passwd) | sudo -A smbpasswd username -s
options:
-L local mode (must be first option)
-h print this usage message
-s use stdin for password prompt #-s就是标准输出
-c smb.conf file Use the given path to the smb.conf file
-D LEVEL debug level
-r MACHINE remote machine
-U USER remote username (e.g. SAM/user)
extra options when run by root or in local mode:
-a add user
-d disable user
-e enable user
-i interdomain trust account
-m machine trust account
-n set no password
-W use stdin ldap admin password
-w PASSWORD ldap admin password
-x delete user
-R ORDER name resolve order
上面的脚本分解步骤是:
echo "password" |passwd --stdin user
Usage: passwd [OPTION...] <accountName>
-k, --keep-tokens keep non-expired authentication tokens
-d, --delete delete the password for the named account (root only)
-l, --lock lock the password for the named account (root only)
-u, --unlock unlock the password for the named account (root only)
-e, --expire expire the password for the named account (root only)
-f, --force force operation
-x, --maximum=DAYS maximum password lifetime (root only)
-n, --minimum=DAYS minimum password lifetime (root only)
-w, --warning=DAYS number of days warning users receives before password expiration (root only)
-i, --inactive=DAYS number of days after password expiration when an account becomes disabled (root only)
-S, --status report password status on the named account (root only)
--stdin read new tokens from stdin (root only)
不过,当使用该命令进行批量修改机器密码时可以通过history查看到。
70 echo "zgh234" |passwd --stdin root
71 history
72 passwd --help
73 history
参考链接:https://blog.csdn.net/nfer_zhuang/article/details/42454283