Created
June 28, 2021 14:54
-
-
Save AlexTalker/b97ff853ca2d715f59acaf6b139ccd17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
function cat_passwd_column() { | |
awk -F: '{ print $2; }' | |
} | |
function cat_passwd_salt() { | |
awk -F'$' '{ print $3; }' | |
} | |
function get_shadow() { | |
local USERNAME="$1" | |
getent shadow "$USERNAME" | |
} | |
USERNAME="$1" | |
PASSWORD="$2" | |
get_shadow "$USERNAME" | cat_passwd_column | |
echo -n "$PASSWORD" | openssl passwd -1 -stdin -salt "$(get_shadow "$USERNAME" | cat_passwd_column | cat_passwd_salt)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment