Skip to content

Instantly share code, notes, and snippets.

@poplarShift
Last active February 4, 2025 13:47
Show Gist options
  • Save poplarShift/ad791de5b17620ca98b235092fb364c4 to your computer and use it in GitHub Desktop.
Save poplarShift/ad791de5b17620ca98b235092fb364c4 to your computer and use it in GitHub Desktop.
Automatically enter OATH and password for ssh authentication
#!/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