【问题标题】:Shell Script to verify root pw用于验证 root pw 的 Shell 脚本
【发布时间】:2014-07-17 19:10:56
【问题描述】:

我有一个将用户添加到 linux 系统的脚本。我打算有一个步骤将根 pw 设置为默认值,但是如果没有脚本中的明文密码,我怎么能做到这一点?

【问题讨论】:

    标签: linux bash passwords


    【解决方案1】:

    查看手册页中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,然后使用 -p 在我的脚本中使用加密版本吗?
    • 运行一次openssl passwd 并使用usermod -p 的加密密码。
    • 谢谢——难道不能有人将加密的密码从 shell 脚本中取出并使用 openssl 将其解密回原始形式吗?
    • 不使用 openssl。以保护 /etc/shadow 的方式保护您的脚本,并强制您的用户在首次登录时更改密码。
    【解决方案2】:

    一种方法可能是让您的脚本将新用户信息写入文件。然后,有另一个脚本(由 root 执行)使用 useradd 命令实际添加新用户。也许第二个脚本可以是每几分钟运行一次的 cron 作业。它不会是实时的,但我会觉得这样做的安全性会更好,而不是在面向公众的脚本中使用 root 密码。

    【讨论】:

      猜你喜欢
      • 2023-04-06
      • 1970-01-01
      • 2019-02-20
      • 2014-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多