Skip to content

Instantly share code, notes, and snippets.

@beezly
Created September 9, 2019 13:09
Show Gist options
  • Save beezly/2e4ad73bb5055f4c56b2018760d0b11c to your computer and use it in GitHub Desktop.
Save beezly/2e4ad73bb5055f4c56b2018760d0b11c to your computer and use it in GitHub Desktop.
Use kpasswd to rotate through a number of passwords between your old and new passwords
#!/usr/bin/env bash
CYCLE=24
declare -a PASSWORDS
let last_cycle=CYCLE+1
PASSWORDS[0]=$1
PASSWORDS[${last_cycle}]=$2
for i in $(seq ${last_cycle}); do
echo $i
if [[ $i -ne $last_cycle ]]; then
password=$(pwgen -y -r \'\"'\{}$[]#;!' 10 1)
PASSWORDS[${i}]=${password}
else
password=${PASSWORDS[${i}]}
fi
export NEW_PASSWORD=${password}
let last_i=i-1
export CURRENT_PASSWORD=${PASSWORDS[$last_i]}
expect <<EOD
spawn kpasswd
expect {
{Password: } {
send "${CURRENT_PASSWORD}\r"
exp_continue
}
{New password: } {
send "${NEW_PASSWORD}\r"
exp_continue
}
{Success} {
return 0
}
-re '.*' {
return 1
}
}
EOD
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment