【发布时间】:2014-07-17 19:10:56
【问题描述】:
我有一个将用户添加到 linux 系统的脚本。我打算有一个步骤将根 pw 设置为默认值,但是如果没有脚本中的明文密码,我怎么能做到这一点?
【问题讨论】:
我有一个将用户添加到 linux 系统的脚本。我打算有一个步骤将根 pw 设置为默认值,但是如果没有脚本中的明文密码,我怎么能做到这一点?
【问题讨论】:
查看手册页中usermod 的选项“-p”:
-p, --password PASSWORD
The encrypted password, as returned by crypt(3).
Note: This option is not recommended because the password (or encrypted
password) will be visible by users listing the processes.
The password will be written in the local /etc/passwd or /etc/shadow file.
This might differ from the password database configured in your PAM
configuration. You should make sure the password respects the system's
password policy.
【讨论】:
openssl passwd 并使用usermod -p 的加密密码。
一种方法可能是让您的脚本将新用户信息写入文件。然后,有另一个脚本(由 root 执行)使用 useradd 命令实际添加新用户。也许第二个脚本可以是每几分钟运行一次的 cron 作业。它不会是实时的,但我会觉得这样做的安全性会更好,而不是在面向公众的脚本中使用 root 密码。
【讨论】: