如何使用基于时间的一次性密码非交互式地提供ssh?

问题描述 投票:-1回答:1

一些超级计算机需要基于时间的一次性密码(OTP)才能通过ssh登录。我想避免每次都输入密码并通过bash脚本自动执行login / scp / rsync,我会生成一次性密码,然后使用sshpass将一次性密码传递给ssh:

sshpass -p my_password_and_OTP ssh user@hostname

这个sshpass适用于通常的ssh,但我的测试表明它不适用于需要一次性密码的ssh。我想知道是否有一种方法可以通过基于时间的一次性密码非交互式地提供ssh。

bash ssh expect one-time-password
1个回答
0
投票

这是我使用expect + oathtool的解决方案:

#!/usr/bin/expect -f
set otp [exec oathtool --totp -b my_secrete_key]
set timeout -1
spawn scp a.f90 [email protected]:~/
expect "Password + OTP:"
send -- "my_passwd${otp}\r"
expect eof

我使用oathtool生成一次性密码并将结果存储在变量otp中。

© www.soinside.com 2019 - 2024. All rights reserved.