Ruby 中使用 net-sftp 的基于密码密钥的身份验证

Passphrase Key-based authenication with net-sftp in Ruby

根据问题 Key based authenication with net-sftp in Ruby,我可以使用以下方法使用基于密钥的身份验证 SFTP:

Net::SFTP.start(host, "user", keys:['~/.ssh/my_key']) do |sftp|
   sftp.upload! "/local/file.tgz", "/remote/file.tgz"
end

但我无法让这对需要密码的密钥起作用——我只是收到用户登录该主机的提示。我是否遗漏了一些可以让我输入密钥密码的内容?还是我需要坚持使用 ssh-agent

passphrase 选项:

the passphrase to use when loading a private key (default is nil, for no passphrase)

如果您没有指定 passphrase,除非您使用 non_interactive 选项,否则系统会要求您提供一个:

set to true if your app is non interactive and prefers authentication failure vs password prompt

non interactive applications should set it to true to prefer failing a password/etc auth methods vs asking for password