我已经尝试了一些在SL 6.5上生成encryption密码的不同方法,但似乎没有任何效果。 我在各种/ var / log / anaconda *文件中找不到任何错误,但是我无法login,所以显然无法正常工作。
/root/anaconda-ks.cfg的原始自动创build的文件我用作模板看起来像这样:
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
什么都行不通 我无法login,最终不得不在单用户模式下重置root密码。
确保你的机器上有shadow和passal = sha512,在你的机器上设置你想要的密码,并从/ etc / shadow中取出它,并把它放在kickstart中。 这对于生产使用是不可取的。
要编程,使用生成kickstart文件的所选语言的crypt库:
ruby:
'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)));
Perl的:
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())
使用crypt特定的mksaltreplace对os.random的调用。
请参阅Python标准库:crypt : crypt.mksalt() :“返回指定方法的随机生成的盐。如果未指定方法,则使用方法()返回的最强方法”
编辑 :
1)'$ 6 $'用于SHA512。 您需要用您select的encryptiontypesreplace它。
2)你也可以将其中的任何一个转换成一个衬里,以便从bash中完成。
编辑 (有一个完整的答案,感谢miken32和dawud ):
3)与GNU相比,BSD crypt是一个不同的实现,所以它们不兼容。 如果你想在BSD系统(如OSX)上使用它,你可以使用PHP(使用PHP版本> 5.3.0)版本,因为它实现了它自己的crypt()函数。
Mac上的另一种select是使用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 "")'
这里logging了生成散列密码的方式。
$ 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 crypt中不存在$id$扩展名
对于SHA512,您需要在GNU / Linux机器中生成哈希。
上面的Python例子不完整:
crypt.crypt('password', '$6$' + base64.b64encode(os.urandom(6)))
一个工作class轮将是:
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()))'