哪个能用就用哪个吧!
方法一,
echo -e "newpwd newpwd" | (passwd root)
方法二,
echo "newpwd" | passwd root --stdin > /dev/null 2>&1
方法三,
#如果密码中包含$字符,使用反斜线()进行转义
echo root:newpwd123$|chpasswd
Openwrt | openwrt 编译时,如何指定root密码
cat /etc/shadow
root:$1$HSk7yPlb$6cPCTE8gYv2AxBvGdwCgS/:17949:0:99999:7:::
package/base-files/files/etc/shadow
参考:
https://stackoverflow.com/questions/714915/using-the-passwd-command-from-within-a-shell-script