Last active
February 4, 2025 13:47
-
-
Save poplarShift/ad791de5b17620ca98b235092fb364c4 to your computer and use it in GitHub Desktop.
Automatically enter OATH and password for ssh authentication
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
#!/bin/bash | |
# This is assuming you have the password accessible via `pass` (1st line) | |
# and the OATH secret as the second word of a line starting with "Secret: " | |
# can't pass an EOF directly because that would be hogging stdin (from ssh) | |
script=$(cat <<EOF | |
spawn ssh $@ | |
expect "oath" | |
send -- "$(oathtool --totp -b $(pass PASSWORDNAME |grep Secret: | cut -d ' ' -f2))\r" | |
expect "password" | |
send -- "$(pass PASSWORDNAME|head -n1)\r" | |
interact | |
EOF | |
) | |
expect -c "$script" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment