MAC 终端配置免MFA登陆(动态token)

1、获取MFA_KEY , 笨方法:先使用authentictor扫描MFA二维码,然后下载备份文件,获取该认证的secret码
2、创建xxx.exp格式脚本文件

#!/usr/bin/expect
set kdauth [ exec oathtool --totp -b XXsecretXXX]

trap {
        set rows [stty rows]
        set cols [stty columns]
        stty rows $rows columns $cols < $spawn_out(slave,name)
} WINCH

spawn ssh xx@xx -p xx 
expect {
        "password*" { send "xxxxxxxx
"; exp_continue }
        "auth*" { send "$kdauth
"; interact }
}

2、再次,安装oathtool, 这个工具可以从命令行计算 MFA TOKEN
brew install oath-toolkit

3、执行

expect <你的脚本名称>.exp

4、简易命令 alias

echo "alias serv='expect <你的脚本名称>.exp '" >> ~/.bash_profile && source ~/.bash_profile
原文地址:https://www.cnblogs.com/sihye/p/14411197.html