我找到了一个指南,解释了如何设置用户密码。我正在尝试使其自动化并向用户发送电子邮件,例如:
userid created with password XYZ.
request to change the initial password.
Run Code Online (Sandbox Code Playgroud)
根据上面的文档,需要使用 Python 创建一个加密的密码并将其输入到usermod
命令中,如下所示:
usermod -p "<encrypted-password>" <username>
Run Code Online (Sandbox Code Playgroud)
有没有其他更简单的方法来做到这一点?我不想下载任何特殊的实用程序来做到这一点;它应该尽可能地概括。
编辑:即使上面链接中给出的方法对我来说似乎也不起作用:
bash-3.00# python
Python 2.4.6 (#1, Dec 13 2009, 23:43:51) [C] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> import crypt; print crypt.crypt("<password>","<salt>")
<sOMrcxm7pCPI
>>> ^D
bash-3.00# useradd -g other -p "sOMrcxm7pCPI" -G bin,sys -m -s /usr/bin/bash mukesh2
UX: useradd: ERROR: project sOMrcxm7pCPI does not exist. Choose another.
UX: useradd: sOMrcxm7pCPI …
Run Code Online (Sandbox Code Playgroud)