Not much to say about /etc/passwd and /etc/shadow.
The password stored in /etc/shadow is in the form of
username:$1$X1FNdStG$v8jqD184lDOuPeDoZqOc8.:17281:0:99999:7:::
Mainly look at the middle part
$encryption method&salt& encrypted data
$1$X1FNdStG$v8jqD184lDOuPeDoZqOc8.
so here
Encryption is 1
salt is X1FNdStG
The encrypted password is
v8jqD184lDOuPeDoZqOc8.
Specifically, man crypt can be used to investigate the case. Encryption method 1 is md5 encryption but not standard md5?)
call code to implement
#define _XOPEN_SOURCE #include <stdio.h> #include <unistd.h> int main(int argc, char *argv[]) { char key[20] = "root"; char salt[20] = "$1$X1FNdStG"; printf("%s\n", crypt(key, salt)); return 0; }
use when compiling
gcc -o main main.c -lcrypt
Execute is OK.