【问题标题】:salt-ssh : Disable SSH Host Key Checking with python apisalt-ssh :使用 python api 禁用 SSH 主机密钥检查
【发布时间】:2017-08-14 22:02:08
【问题描述】:

我正在使用 salt-ssh 和命令行,我可以使用选项 -i 来使用“StrictHostKeyChecking”

(agent) [root@NODE ~]# salt-ssh  'af0abc4b-6980d-4fdd-ba63-192cb3d116be' test.ping
af0abc4b-6980d-4fdd-ba63-192cb3d116be:
    ----------
    retcode:
        254
    stderr:
    stdout:
        The host key needs to be accepted, to auto accept run salt-ssh with the -i flag:
        The authenticity of host '10.10.10.10 (10.10.10.10)' can't be established.
        ECDSA key fingerprint is af:00:b8:ab:7a:3e:cd:06:9a:6c:36:e9:32:f0:a3:a4.
        Are you sure you want to continue connecting (yes/no)? 

(agent) [root@NODE ~]# salt-ssh -i --no-host-keys 'af0abc4b-6980d-4fdd-ba63-192cb3d116be' test.ping
af0abc4b-6980d-4fdd-ba63-192cb3d116be:
    True

但是当我想用 python api 做同样的事情时,我没有找到指定 -i 选项的方法,所以可以这样做。

这是我正在使用的python代码

from salt.client.ssh.client import SSHClient
salt = SSHClient()
salt.cmd('af0abc4b-6980d-4fdd-ba63-192cb3d116be', 'test.ping')
Out: 
{'af0abc4b-6980d-4fdd-ba63-192cb3d116be': {'retcode': 254,
  'stderr': '',
  'stdout': "The host key needs to be accepted, to auto accept run salt-ssh with the -i flag:\nThe authenticity of host '10.10.10.10 (10.10.10.10)' can't be established.\nECDSA key fingerprint is af:00:b8:ab:7a:3e:cd:06:9a:6c:36:e9:32:f0:a3:a4.\nAre you sure you want to continue connecting (yes/no)? "}}

我怎样才能对 python 代码做同样的事情??

【问题讨论】:

    标签: python ssh salt


    【解决方案1】:

    我找到的唯一解决方案是在 $HOME/.ssh/config` 中配置 StrictHostKeyChecking

    $HOME/.ssh/config 示例

    Host *
        StrictHostKeyChecking no
    

    Host 10.10.10.15
       StrictHostKeyChecking no
    

    【讨论】:

      猜你喜欢
      • 2019-01-20
      • 2010-12-11
      • 2023-04-02
      • 1970-01-01
      • 2018-09-13
      • 2021-03-26
      • 1970-01-01
      • 1970-01-01
      • 2020-03-03
      相关资源
      最近更新 更多