Skip to content

Instantly share code, notes, and snippets.

@AlexTalker
Created June 28, 2021 14:54
Show Gist options
  • Save AlexTalker/b97ff853ca2d715f59acaf6b139ccd17 to your computer and use it in GitHub Desktop.
Save AlexTalker/b97ff853ca2d715f59acaf6b139ccd17 to your computer and use it in GitHub Desktop.
#!/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