如何使用ansible创建用户和设置密码? [英] How do I create a user and set a password using ansible?
问题描述
The documentation refers us to the github example, but this is a bit sparse and mysterious.
它说:
# created with:
# crypt.crypt('This is my Password', '$1$SomeSalt')
password: $1$SomeSalt$UqddPX3r4kH3UL5jq5/ZI.
但 crypt.crypt
不会发出此示例所示的内容。它也使用MD5。
but crypt.crypt
doesn't emit what the example shows. It also uses MD5.
我试过这个:
# python
import crypt
crypt.crypt('This is my Password', '$6$somereallyniceandbigrandomsalt$')
>> '$69LxCegsnIwI'
但用户的密码字段应该是这样:
but the password field of user should get something like this:
password: $6$somereallyniceandbigrandomsalt$UqddPX3r4kH3UL5jq5/ZI.
其中包含三个 $ 分隔符,用于分隔 6
which includes three $ delimiters separating the 6
(which signifies that its a SHA-512 hash), the salt, and the crypted password.
Note that the python crypt docs don't mention anything about the $N format.
问题:
-
c $ c> crypt.crypt ,应以尾随 $ 结尾或以 $ N $ SALT 格式?
Is the salt, as supplied to
crypt.crypt
, supposed to end with a trailing $ or is it in $N$SALT format?
Python文件是指DES,但是如何调用SHA-512或MD5,并在哪里创建文档?
Python docs refer to DES, but how is SHA-512 or MD5 being called and where is the documention for this?
我真的应该接受 crypt.crypt
的输出,并切断第一个 $ 6 ,并将 $ N $ SALT $ CRYPTED ?这是什么ansible需要吗?
Am I really supposed to take the output of crypt.crypt
and cut off the first $6 and make $N$SALT$CRYPTED? Is this what ansible needs?
推荐答案
文档中显示的python示例取决于您正在使用的操作系统上运行的crypt的版本。
The python example shown in the documentation depends on what version of crypt is running on the OS you are using.
我在OS X上生成了crypt,而目标服务器是ubuntu。
I generated the crypt on OS X and the server I was targetting is ubuntu.
由于操作系统提供crypt的实施方式存在差异,因此结果不同且不兼容。
Due to differences in which implementation of crypt is offered by the OS, the result is different and incompatible.
改用:
http://pythonhosted.org/passlib/
Passlib是Python 2的密码散列库3,它提供
超过30个密码散列算法的跨平台实现,
以及用于管理现有密码散列的框架。它是
设计用于广泛的任务,从验证在/ etc / shadow中找到的哈希
,为
多用户应用程序提供全功能密码哈希。 p>
Passlib is a password hashing library for Python 2 & 3, which provides cross-platform implementations of over 30 password hashing algorithms, as well as a framework for managing existing password hashes. It’s designed to be useful for a wide range of tasks, from verifying a hash found in /etc/shadow, to providing full-strength password hashing for multi-user application.
>>> # import the hash algorithm
>>> from passlib.hash import sha512_crypt
>>> # generate new salt, and hash a password
>>> hash = sha512_crypt.encrypt("password")
>>> hash
'$ 6 $ rounds = 656000 $ BthPsosdEpqOM7Qd $ l / ln9nyEfxM67ea8Bvb79JoW50pGjf6iM87taIvfSmpjasE4 / wBG1.60pFS6W992T7Q1q2wikMbxYUvMHD1tT1'
'$6$rounds=656000$BthPsosdEpqOM7Qd$l/ln9nyEfxM67ea8Bvb79JoW50pGjf6iM87taIvfSmpjasE4/wBG1.60pFS6W992T7Q1q2wikMbxYUvMHD1tT1'
这篇关于如何使用ansible创建用户和设置密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!