Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用私钥执行Testinfra ssh_Python_Ssh_Tdd_Pytest_Private Key - Fatal编程技术网

Python 使用私钥执行Testinfra ssh

Python 使用私钥执行Testinfra ssh,python,ssh,tdd,pytest,private-key,Python,Ssh,Tdd,Pytest,Private Key,使用testinfra(Pytest插件)进行测试。我想使用私钥从Jenkins测试远程主机 [root@jenkins tests]# testinfra --ssh-config=/path/to/private/key \ --sudo --hosts=user@remotehost test.py 在哪里 及 我得到的是 E Exception: Unparsable line -----BEGIN RSA PRIVATE KEY----- /u

使用testinfra(Pytest插件)进行测试。我想使用私钥从Jenkins测试远程主机

[root@jenkins tests]# testinfra --ssh-config=/path/to/private/key \
     --sudo --hosts=user@remotehost test.py
在哪里

我得到的是

E               Exception: Unparsable line -----BEGIN RSA PRIVATE KEY-----

/usr/lib/python2.7/site-packages/paramiko/config.py:68: Exception
================================================================================= warnings summary ==================================================================================
None
  Module already imported so can not be re-written: testinfra

-- Docs: http://doc.pytest.org/en/latest/warnings.html
======================================================================= 1 failed, 1 warnings in 0.23 seconds ========================================================================
似乎paramiko不喜欢这种格式,但尝试了其他后端,但效果并不理想。那么如何传递私钥呢?

--ssh config
必须是sshconfig的路径。您可以在该配置中为主机配置密钥对

类似于~/.ssh/config:

Host remotehost
    User user
    IdentityFile remotehost-key
E               Exception: Unparsable line -----BEGIN RSA PRIVATE KEY-----

/usr/lib/python2.7/site-packages/paramiko/config.py:68: Exception
================================================================================= warnings summary ==================================================================================
None
  Module already imported so can not be re-written: testinfra

-- Docs: http://doc.pytest.org/en/latest/warnings.html
======================================================================= 1 failed, 1 warnings in 0.23 seconds ========================================================================
Host remotehost
    User user
    IdentityFile remotehost-key