最近管理的一批机器,有个需求是要统一修改一个帐号的用户名密码,比如将qa帐号的密码改为1234,后来还为了脚本化,很方便的执行,还使用了非交互式地修改用户的密码。简单记录一下吧。 1. 交互式配置本地用户的密码:passwd 命令 复制代码 代码如下: [root@host_221-81 ~]# passwd qa Changing password for user qa. New password: BAD PASSWORD: it is too short BAD PASSWORD: is too simple Retype new password: passwd: all authentication tokens updated successfully.
注意:脚本的第二行,这种写法可能比较陌生,这是在TCL语言中的语法,The backslash is recognized as part of a comment to sh, but in Tcl the backslash continues the comment into the next line which keeps the exec command from executing again. 该脚本的执行结果为: 复制代码 代码如下: [root@smilejay ~]# ./change-pwd-expect.sh qa 1234 spawn passwd qa Changing password for user qa. New password: BAD PASSWORD: it is too short BAD PASSWORD: is too simple Retype new password: passwd: all authentication tokens updated successfully.