【问题标题】:Non-interactively ssh to server but interactively非交互式 ssh 到服务器但交互式
【发布时间】:2011-12-21 05:08:04
【问题描述】:

我了解以这种方式使用 ssh 的所有安全风险,但我现在需要的是能够登录到 target 服务器并执行 foo 命令并获取的几行 (bash) shell 脚本返回源主机,类似于:

while true
do
   ssh target foo   # Here I get the prompt for a password which
                    # I would like to give non-interactively
   sleep 1
done

不想使用基于 ssh 密钥的身份验证,因为我真正需要的是每秒(左右)模拟一次交互式登录过程(但不是交互式!)。

【问题讨论】:

    标签: bash login ssh sh ssh-keys


    【解决方案1】:

    您需要使用expect 编写脚本,例如perl

    编辑:您也可以尝试直接在bash 中编写expect 脚本。

    【讨论】:

      【解决方案2】:

      您必须编辑 SSH 服务器以允许仅基于密钥而不是密码登录。

      试试看this能不能帮到你。

      当然如果不能编辑服务器配置,需要查看其他解决方案

      【讨论】:

        【解决方案3】:

        sshpass 旨在以编程方式而非交互方式为 ssh 提供密码。所以你可以用例如替换ssh target foo sshpass -f passwordfile ssh target foo.

        【讨论】:

          猜你喜欢
          • 2013-04-16
          • 2012-02-02
          • 1970-01-01
          • 2010-11-26
          • 2012-10-18
          • 2018-01-20
          • 2016-04-16
          • 1970-01-01
          • 2016-08-27
          相关资源
          最近更新 更多