【问题标题】:How to supply keys when calling a bash in ruby在 ruby​​ 中调用 bash 时如何提供密钥
【发布时间】:2019-01-10 23:38:36
【问题描述】:

使用 Ruby,我试图从另一台机器上的文件中获取内容:

run_this = `ssh user@thecomputer cat myfile.txt`

问题是第一次运行,它正在等待引入'yes'或'no':

无法确定主机“计算机(11.12.134.46)”的真实性。 ECDSA 密钥指纹为 SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxx。 确定要继续连接(是/否)?

我需要在没有人工干预的情况下自动提供“是”

我该怎么做?

【问题讨论】:

  • 嗨@Mario Ruiz,你能提供更多代码吗?
  • 这就是全部代码
  • 调用时尽量避免反引号,这是一种草率的方法。而是使用system,其中每个参数分别传入:system("ssh","user@computer", "...")
  • 看看yes 程序。 yes | ssh user@thecomputer cat myfile.txt 能解决你的问题吗?
  • 什么都不做

标签: ruby bash ubuntu ssh


【解决方案1】:
run_this = `ssh -oStrictHostKeyChecking=no user@thecomputer cat myfile.txt`

如果没有关闭 StrictHostKeyChecking 选项,ssh 通常默认不信任任何新主机,如果有新主机,会以交互方式提示用户,否则会失败。

您遇到的问题很常见。例如,这里有人试图用 rsync 解决这个 ssh 行为:

Bypass Rsync Prompt "Are you sure you want to continue connecting"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-20
    • 2021-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-18
    相关资源
    最近更新 更多