Skip to content

Instantly share code, notes, and snippets.

@pengzhendong
Created July 6, 2020 01:35
Show Gist options
  • Save pengzhendong/7316ba0e60fafb53f50101d841de6b28 to your computer and use it in GitHub Desktop.
Save pengzhendong/7316ba0e60fafb53f50101d841de6b28 to your computer and use it in GitHub Desktop.
#!/usr/bin/expect
trap {
set XZ [stty rows]
set YZ [stty columns]
stty rows $XZ columns $YZ < $spawn_out(slave, name)
} WINCH
set timeout 2
set HOST [lindex $argv 0]
set USER <Your Google Authenticator username>
set KEY <Your Google Authenticator key>
spawn ssh -t $USER@<JumpServer name> ssh $HOST
expect "Verification code: " {
set CODE [exec oathtool --totp -b -d 6 $KEY]
send "$CODE\r"
}
expect "<Username>@<Server name>" {
send "cd $USER; exec /bin/bash --rcfile .bashrc\r"
}
interact
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment