如今不少团队都在使用 jumpserver(http://www.jumpserver.org/ )做为跳板机,管理服务器权限,一些对安全要求比较高的团队还会加上 Google authenticator (Google 身份验证器)。python
可是安全和方便就是跷跷板的两端,太安全了,就会不方便。安全
每次登陆跳板机还要打开手机输入 Google authenticator 的安全码,有点蛋疼,效率也低。服务器
SecureCRT 能够使用 python 实现自动登陆架构
安装 Google authenticator 的 python 实现python2.7
pip install pyotp
自动登陆脚本ssh
# $language = "python" # $interface = "1.0" # This automatically generated script may need to be # edited in order to work correctly. import sys,pyotp sys.path.insert(0, "/usr/local/lib/python2.7/site-packages") // 这里是pip install pyotp以后,pip 的 packeages 目录,否则会报 import Error def Main(): crt.Screen.Synchronous = True crt.Screen.WaitForString("Google authenticator:") // 这里输入跳板机提示输入安全码的字符串 totp = pyotp.TOTP('base32secret3232') // 这里输入你的 Google authenticator 密钥,若是是二维码,就把二维码解析出来,把密钥粘贴进去 crt.Screen.Send(totp.now()) crt.Screen.Send("\015") Main()
启动python,用下面的方法这里能够获取 pip packeages 的安装路径3d
>>> import sys >>> print(sys.path) ['', '/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages'] >>>
而后根据把上面定义好的自动登陆脚本配置在红框处code
验证方式选下面这两种 server
这个自动登陆脚本,能够直达你想去的服务器blog
# $language = "python" # $interface = "1.0" # This automatically generated script may need to be # edited in order to work correctly. import sys,pyotp sys.path.insert(0, "/usr/local/lib/python2.7/site-packages") def Main(): crt.Screen.Synchronous = True crt.Screen.WaitForString("Google authenticator:") // 这里输入跳板机提示输入安全码的字符串 totp = pyotp.TOTP('base32secret3232') crt.Screen.Send(totp.now()) crt.Screen.Send("\015") crt.Screen.WaitForString("Opt> ") crt.Screen.Send("/" + "\015") crt.Screen.WaitForString("Opt> ") crt.Screen.Send("这里填ip地址" + "\015") Main()
再强调一下这句话,安全和方便就是跷跷板的两段,本身要作一个权衡
最后,若是是用 ssh 命令登陆服务器的,能够使用 expect 脚本实现相似的效果。
更多架构、PHP、GO相关踩坑实践技巧请关注个人公众号:PHP架构师