Linux -通过脚本为用户设置新的随机密码



我正在用bash编写一个脚本。其中一部分是为用户设置一个新的随机密码。现在,我使用pwgen工具生成随机密码。它看起来像

pwgen -s 13 10 | head -1 > pasChange.txt
cat pasChange.txt: NOy3a8S53Jged

如何设置随机密码作为用户密码?如果你有不同的方法,我会很高兴听到。谢谢!

我找到了一个简单的解决方案,适合任何感兴趣的人。

sudo apt-get install pwgen                    ## Install pgwen
pwgen -s 13 10 |head -1 > change_pas.txt      ## Insert random string into txt file  
yes `cat change_pas.txt` | sudo passwd pi     ## Change the password to the string in 
the txt file

最新更新