Skip to content

Instantly share code, notes, and snippets.

@marcellourbani
Last active August 31, 2022 22:14
Show Gist options
  • Save marcellourbani/dd9f92fc5ec1e22ba24ac7d2585a3bed to your computer and use it in GitHub Desktop.
Save marcellourbani/dd9f92fc5ec1e22ba24ac7d2585a3bed to your computer and use it in GitHub Desktop.
Automated OTP responder based on fish shell - maybe not a great idea but convenient :)
#!/usr/bin/fish
while true
set resp (inotifywait /run/systemd/ask-password -e moved_to)
set file = (string split ' ' $resp)
set pfile "/run/systemd/ask-password/$file[4]"
if grep "$CHALLENGE_KEY" $pfile >/dev/null
set socket (grep -i socket $pfile | sed s/socket=//i)
set ticket (oathtool -b --totp "$OTP_KEY")
echo socket "$socket"
echo "$ticket" | /lib/systemd/systemd-reply-password 1 "$socket"
echo code sent
end
end
[Unit]
Description=OTP responder
[Service]
Type=simple
Environment=CHALLENGE_KEY=mychallengekey
Environment=OTP_KEY=myotpkey
ExecStart=/usr/local/bin/otpresponder
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment