Skip to content

Instantly share code, notes, and snippets.

@enif-lee
Created July 19, 2024 00:52
Show Gist options
  • Save enif-lee/77460cc6da3c9c04c24026bfaea6c62e to your computer and use it in GitHub Desktop.
Save enif-lee/77460cc6da3c9c04c24026bfaea6c62e to your computer and use it in GitHub Desktop.
function bw_unlock() {
if ! bw unlock --check;
then
export BW_SESSION="$(bw unlock --raw)"
fi
}
function tsh_login() {
bw_unlock
password=$(bw get password <teleport-vault-name>)
otp=$(bw get totp <teleport-vault-name>)
user=<your_name>
if ! tsh status; then
expect -c "
spawn tsh login --proxy=teleport.iamport.co --user=$user --auth=local --mfa-mode=otp
expect {
-re \"Enter password for Teleport user $user:\" {
send -- \"$password\r\"
exp_continue
}
-re \"Enter an OTP code from a device:\" {
send -- \"$otp\r\"
}
}
interact
"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment