在 Linux 上创建新用户时,我应该给 crypt 多少盐?
What value of salt should I give to crypt to create a new user on Linux?
我正在编写一个 Perl 脚本,它将创建一个新用户(Ubuntu)。
需要按照
的步骤
$encrypted_password = crypt ($password, $salt);
system ("useradd -d $home -s /bin/bash -g $group -p $encrypted_password $name");
$salt
的值应该是多少? Internet 上的示例似乎使用了任意值,但如果加密密码要根据用户输入的内容进行测试,则内核需要使用 same salt 对输入进行散列,以便才能通过比较。
This website 声称盐是在 crypt
的输出中编码的,但这显然不是真的。
在 Perl 中
的输出
print crypt("foo", "aa");
print crypt("foo", "aabbcc");
print crypt("foo", "aa1kjhg23gh43jhgk32kh325423g");
print crypt("foo", "abbbcc");
是
aaKNIEDOaueR6
aaKNIEDOaueR6
aaKNIEDOaueR6
abQ9KY.KfrYrc
除了来自不同盐的相同散列(这是可疑的)之外,似乎只使用了盐的前两个字符。从安全的角度来看,这没有意义。此外,输出的格式也不是上面 link 中声明的格式。
那么在为 useradd
加密密码时我应该使用什么盐值?
关于crypt
的所有信息都在perldoc -f crypt。
这是回答您问题的部分:
When choosing a new salt create a random two character string whose characters come from the set [./0-9A-Za-z] (like join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64] ). This set of characters is just a recommendation; the characters allowed in the salt depend solely on your system's crypt library, and Perl can't restrict what salts crypt() accepts.
希望对您有所帮助。
我正在编写一个 Perl 脚本,它将创建一个新用户(Ubuntu)。
需要按照
的步骤$encrypted_password = crypt ($password, $salt);
system ("useradd -d $home -s /bin/bash -g $group -p $encrypted_password $name");
$salt
的值应该是多少? Internet 上的示例似乎使用了任意值,但如果加密密码要根据用户输入的内容进行测试,则内核需要使用 same salt 对输入进行散列,以便才能通过比较。
This website 声称盐是在 crypt
的输出中编码的,但这显然不是真的。
在 Perl 中
的输出print crypt("foo", "aa");
print crypt("foo", "aabbcc");
print crypt("foo", "aa1kjhg23gh43jhgk32kh325423g");
print crypt("foo", "abbbcc");
是
aaKNIEDOaueR6
aaKNIEDOaueR6
aaKNIEDOaueR6
abQ9KY.KfrYrc
除了来自不同盐的相同散列(这是可疑的)之外,似乎只使用了盐的前两个字符。从安全的角度来看,这没有意义。此外,输出的格式也不是上面 link 中声明的格式。
那么在为 useradd
加密密码时我应该使用什么盐值?
关于crypt
的所有信息都在perldoc -f crypt。
这是回答您问题的部分:
When choosing a new salt create a random two character string whose characters come from the set [./0-9A-Za-z] (like join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64] ). This set of characters is just a recommendation; the characters allowed in the salt depend solely on your system's crypt library, and Perl can't restrict what salts crypt() accepts.
希望对您有所帮助。