AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 588532
Accepted
miken32
miken32
Asked: 2014-04-12 15:38:53 +0800 CST2014-04-12 15:38:53 +0800 CST 2014-04-12 15:38:53 +0800 CST

Anaconda kickstart 和 rootpw 选项

  • 772

我已经尝试了几种在 SL 6.5 上生成加密密码的不同方法,但似乎没有什么对我有用。我在各种 /var/log/anaconda* 文件中的任何地方都没有发现任何错误,但我无法登录,所以它显然不起作用。

/root/anaconda-ks.cfg我用作模板的原始自动创建文件如下所示:

rootpw  --iscrypted $6$...(about 100 characters)
authconfig --enableshadow --passalgo=sha512

接下来我尝试openssl passwd -1了它给了我:

rootpw  --iscrypted $1$...(about 30 characters)
authconfig --enableshadow --passalgo=sha512

我意识到这不是 SHA-512,所以我尝试了一个在几个地方重复的 Python 单线:

rootpw  --iscrypted $6...(about 10 characters)
authconfig --enableshadow --passalgo=sha512

没有任何作用;我无法登录,最终不得不在单用户模式下重置 root 密码。

rhel6
  • 4 4 个回答
  • 15183 Views

4 个回答

  • Voted
  1. Best Answer
    Florin Asăvoaie
    2014-04-12T20:49:36+08:002014-04-12T20:49:36+08:00

    确保您的机器上有 shadow 和 passalgo=sha512,将 root 密码设置为您想要在该机器上使用的任何密码,然后从 /etc/shadow 中获取并将其放入 kickstart。这不建议用于生产用途。

    要以编程方式进行,请使用生成 kickstart 文件的所选语言的 crypt 库:

    红宝石:

    'password'.crypt('$6$' + (Base64.encode64(6.times.map{ Random.rand(256).chr }.join)).strip)
    

    PHP:

    crypt ('password', '$6$' . base64_encode (openssl_random_pseudo_bytes(6)));
    

    珀尔:

    crypt ('password', '$6$' . encode_base64 (join '' => map chr (rand (256)), 0..5))
    

    Python:

    crypt.crypt('password', '$6$' + base64.b64encode(os.urandom(6)))
    

    强烈建议您每次都使用随机盐,就像我在这里所做的那样,特别是如果您在所有服务器上使用相同的密码。

    编辑: Python 3:

    crypt.crypt("password", crypt.mksalt())
    

    将调用替换为os.randomcrypt 特定的mksalt.

    请参阅Python 标准库:crypt : crypt.mksalt():“返回指定方法的随机生成的盐。如果没有给出方法,则使用由 methods() 返回的最强方法”

    编辑:

    1) '$6$' 用于 SHA512。您需要将其替换为您选择的加密类型。

    2)您也可以将其中任何一个转换为一个衬里,以便从 bash 中完成。

    编辑(有一个完整的答案,感谢miken32和dawud):

    3)与 GNU 相比,BSD crypt 是一种不同的实现,因此它们不兼容。如果您想在 BSD 系统(如 OSX)上使用它,您可以使用 PHP(PHP 版本 > 5.3.0)版本,因为它实现了自己的crypt()函数。

    mac 上的另一种选择是使用passlib:

    python -c 'import getpass; import passlib.hash; h=passlib.hash.sha512_crypt.hash(getpass.getpass()); print(h if (passlib.hash.sha512_crypt.verify(getpass.getpass("Confirm:"), h)) else "")'
    

    或者,使用 glibc 的默认编号。回合数(5000):

    python -c 'import getpass; import passlib.hash; h=passlib.hash.sha512_crypt.using(rounds=5000).hash(getpass.getpass()); print(h if (passlib.hash.sha512_crypt.verify(getpass.getpass("Confirm:"), h)) else "")'
    
    • 5
  2. dawud
    2014-04-13T01:15:36+08:002014-04-13T01:15:36+08:00

    此处记录了生成散列密码的方式。

    $ python -c 'import crypt; print(crypt.crypt("My Password", "$6$My salt"))'
    

    它不适合您的原因是因为您使用 Mac 来生成哈希。该crypt实现与 GNU/Linux 不同。

    从crypt(3)手册页:

       Glibc notes
       The glibc2 version of  this  function  supports  additional  encryption
       algorithms.
    
       If  salt is a character string starting with the characters "$id$" fol-
       lowed by a string terminated by "$":
    
              $id$salt$encrypted
    
       then instead of using the DES machine,  id  identifies  the  encryption
       method  used  and  this  then  determines  how the rest of the password
       string is interpreted.  The following values of id are supported:
    
              ID  | Method
              ---------------------------------------------------------
              1   | MD5
              2a  | Blowfish (not in mainline glibc; added in some
                  | Linux distributions)
              5   | SHA-256 (since glibc 2.7)
              6   | SHA-512 (since glibc 2.7)
    
       So   $5$salt$encrypted   is   an   SHA-256   encoded    password    and
       $6$salt$encrypted is an SHA-512 encoded one.
    
       "salt" stands for the up to 16 characters following "$id$" in the salt.
       The encrypted part of the password string is the actual computed  pass-
       word.  The size of this string is fixed:
    
       MD5     | 22 characters
       SHA-256 | 43 characters
       SHA-512 | 86 characters
    
       The  characters  in  "salt"  and  "encrypted"  are  drawn  from the set
       [a-zA-Z0-9./].  In the MD5 and SHA implementations the  entire  key  is
       significant (instead of only the first 8 bytes in DES).
    

    OSX$id$中不存在该扩展crypt

    对于 SHA512,您需要在 GNU/Linux 机器中生成哈希。

    • 3
  3. mastash3ff
    2018-01-18T08:37:15+08:002018-01-18T08:37:15+08:00

    有关为 kickstart 选项生成散列密码的更多信息的新文档位置--iscrypted::

    http://pykickstart.readthedocs.io/en/latest/kickstart-docs.html#rootpw

    python -c 'import crypt; print(crypt.crypt("My Password", "$6$My Salt"))

    这将使用您提供的 salt 生成密码的 sha512 crypt。

    • 1
  4. Ole Holm Nielsen
    2015-07-18T04:05:42+08:002015-07-18T04:05:42+08:00

    上面的 Python 示例不完整:

    crypt.crypt('password', '$6$' + base64.b64encode(os.urandom(6)))
    

    一个工作的单线将是:

    python -c 'import crypt,base64,os; print(crypt.crypt("password", "$6$" + base64.b64encode(os.urandom(6))))'
    

    在 Python 3 下

    python -c 'import crypt; print(crypt.crypt("password", crypt.mksalt()))'
    
    • 0

相关问题

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve