Bel*_*dez 67 linux encryption authentication md5
我之前看到的 SF 问题导致了产生 MD5 散列密码的答案。
有没有人有关于生成 SHA-512 散列密码的建议?我更喜欢单衬而不是脚本,但是,如果脚本是唯一的解决方案,那也没关系。
用这个替换以前的 py2 版本:
python3 -c "import crypt;print(crypt.crypt(input('clear-text pw: '), crypt.mksalt(crypt.METHOD_SHA512)))"
Run Code Online (Sandbox Code Playgroud)
dav*_*vey 72
这是一个单班轮:
python -c 'import crypt; print crypt.crypt("test", "$6$random_salt")'
Run Code Online (Sandbox Code Playgroud)
Python 3.3+ 包含mksalt在 crypt 中,这使得使用起来更容易(也更安全):
python3 -c 'import crypt; print(crypt.crypt("test", crypt.mksalt(crypt.METHOD_SHA512)))'
Run Code Online (Sandbox Code Playgroud)
如果你不提供一个参数crypt.mksalt(它可以接受crypt.METHOD_CRYPT,...MD5,SHA256,和SHA512),它会使用最强可用。
哈希的 ID(第一个之后的数字$)与使用的方法有关:
我建议您查看什么是盐等,并根据 smallclamgers 评论加密和散列之间的区别。
更新 1:生成的字符串适用于 shadow 和 kickstart 脚本。
更新 2:警告。如果您使用的是 Mac,请参阅有关在 mac 上的 python 中使用它的评论,它似乎没有按预期工作。
在Mac OS,你应该不使用上述版本,因为Python使用系统的版本crypt(),其行为不安全感DES加密相同和用途。您可以使用此平台独立的单衬(需要 passlib – 安装pip3 install passlib):
python3 -c 'import passlib.hash; print(passlib.hash.sha512_crypt.hash("test"))'
Run Code Online (Sandbox Code Playgroud)
mro*_*ssi 40
在 Debian 上,您可以使用 mkpasswd 来创建具有适合 /etc/shadow 的不同散列算法的密码。它包含在包 whois 中(根据 apt-file)
mkpasswd -m sha-512
mkpasswd -m md5
Run Code Online (Sandbox Code Playgroud)
获取可用散列算法类型的列表:
mkpasswd -m help
Run Code Online (Sandbox Code Playgroud)
HTH
小智 25
最佳答案: grub-crypt
Usage: grub-crypt [OPTION]...
Encrypt a password.
-h, --helpPrint this message and exit
-v, --version Print the version information and exit
--md5 Use MD5 to encrypt the password
--sha-256 Use SHA-256 to encrypt the password
**--sha-512 Use SHA-512 to encrypt the password (default)**
Run Code Online (Sandbox Code Playgroud)
小智 15
这是在各种 Unix 类型操作系统上生成 SHA-512 密码的简短 C 代码。
文件: passwd-sha512.c
#define _XOPEN_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
if ( argc < 3 || (int) strlen(argv[2]) > 16 ) {
printf("usage: %s password salt\n", argv[0]);
printf("--salt must not larger than 16 characters\n");
return;
}
char salt[21];
sprintf(salt, "$6$%s$", argv[2]);
printf("%s\n", crypt((char*) argv[1], (char*) salt));
return;
}
Run Code Online (Sandbox Code Playgroud)
编译:
/usr/bin/gcc -lcrypt -o passwd-sha512 passwd-sha512.c
Run Code Online (Sandbox Code Playgroud)
用法:
passwd-sha512 <password> <salt (16 chars max)>
Run Code Online (Sandbox Code Playgroud)
令人惊讶的是,没有答案暗示openssl passwd带有-6选项的简单命令。也许它在 2011 年还不可用?
如果您不在乎在命令行上提供密码(冒着将其保留在命令历史记录中的风险),那么您可以执行以下操作:
openssl passwd -6 YourPassword
Run Code Online (Sandbox Code Playgroud)
它将生成盐,并输出如下一行:
$6$/57kpVAA/kuPUtzV$Ugxo0RTL2uXCvU7WH43c1qn0quMy2ve.qiBYJPG75tFgTN8gI5Jp/FYPXFOzIsASqVTqM42kjN2805VYLHKzm1
Run Code Online (Sandbox Code Playgroud)
使用该stdin选项,它还可以从 STDIN(或文件)读取密码,因此您不会将其留在历史记录中:
openssl passwd -6 -stdin
Run Code Online (Sandbox Code Playgroud)