Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.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 如何在Paramiko中模拟我们自己的ssh二进制文件?_Python_Ssh_Paramiko - Fatal编程技术网

Python 如何在Paramiko中模拟我们自己的ssh二进制文件?

Python 如何在Paramiko中模拟我们自己的ssh二进制文件?,python,ssh,paramiko,Python,Ssh,Paramiko,我有一个命令,比如 ssh -S myAuthServer hostname 正在尝试创建代码段,我不确定如何实现-S部分 我目前拥有的代码: #!/usr/bin/python import paramiko from paramiko import SSHClient, SSHConfig, SSHException paramiko.util.log_to_file("/tmp/script.log") def getSSHConnection(): config = SS

我有一个命令,比如

ssh -S myAuthServer hostname
正在尝试创建代码段,我不确定如何实现
-S
部分 我目前拥有的代码:

#!/usr/bin/python

import paramiko
from paramiko import SSHClient, SSHConfig, SSHException

paramiko.util.log_to_file("/tmp/script.log")

def getSSHConnection():
    config = SSHConfig()


    host='server1'        

    # setup SSH client
    client = SSHClient()
    client.load_system_host_keys()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    #Check for proxy settings
    proxy = paramiko.ProxyCommand('ssh -S myAuthServer root@%s' % host)
    print "proxy:", proxy

    #Setup the SSH connection
    try:
        if (proxy is None):
            client.connect(host, port=22, username='root')
        else:
            print "-> Using paramiko with proxy"
            client.connect(host, port=22, username='root', sock=proxy)

    except SSHException, ex:
        print ex

    if client:
        stdin, stdout, stderr = client.exec_command('hostname')
        tables=stdout.readlines()

        print "stdin:", stdin
        print "stdout:", stdout
        print "stderr:", stderr
        print "tables:", tables    

    return client

getSSHConnection()
我收到的错误是

INF [20181011-11:14:55.131] thr=1   paramiko.hostkeys: Unable to handle key of type 1024
DEB [20181011-11:14:55.161] thr=2   paramiko.transport: starting thread (client mode): 0x4f35fd0L
DEB [20181011-11:14:55.161] thr=2   paramiko.transport: Local version/idstring: SSH-2.0-paramiko_2.2.1
ERR [20181011-11:15:10.242] thr=2   paramiko.transport: Exception: Error reading SSH protocol banner
ERR [20181011-11:15:10.245] thr=2   paramiko.transport: Traceback (most recent call last):
ERR [20181011-11:15:10.246] thr=2   paramiko.transport:   File "/Users/root/Library/Python/2.7/lib/python/site-packages/paramiko/transport.py", line 1805, in run
ERR [20181011-11:15:10.246] thr=2   paramiko.transport:     self._check_banner()
ERR [20181011-11:15:10.246] thr=2   paramiko.transport:   File "/Users/root/Library/Python/2.7/lib/python/site-packages/paramiko/transport.py", line 1957, in _check_banner
ERR [20181011-11:15:10.246] thr=2   paramiko.transport:     'Error reading SSH protocol banner' + str(e)
ERR [20181011-11:15:10.246] thr=2   paramiko.transport: SSHException: Error reading SSH protocol banner
ERR [20181011-11:15:10.246] thr=2   paramiko.transport:

您不能让Paramiko将
oursshbinary
用作SSH实现。您甚至不能让它使用
ssh

Paramiko是
ssh
本身。

这是一样的(正如你现在知道的),好像你想要
ssh
使用
oursshbinary
(这没有意义)。你必须让帕拉米科做我们的家庭所做的事。但是我们不知道与ssh相比,
oursshbinary
做了什么


对您先前问题的答复:

OpenSSH
ssh
客户端的
-S
开关创建了一个连接共享,该连接共享可被
ssh
的其他实例或其他OpenSSH工具(如
sftp
)重用

Paramiko不支持连接共享。实际上这样做是没有意义的

连接共享对于工具/应用程序很有意义。工具的一个实例创建连接,相同或不同工具的其他实例可以重用该连接

但在脚本/编程时不需要这样做。您有您的SSH会话实例。在整个脚本/程序中,您可以将其用于多种目的。换句话说,您可以共享您的实例


具体来说,使用SSH,OpenSSH连接共享为共享客户端打开单独的SSH通道。使用Paramiko,您还可以通过同一SSH连接打开多个单独的通道。这就是像
Transport.open_sftp_client
(或
SSHClient.open_sftp
),
Transport.open_session
SSHClient.invoke_shell
SSHClient.exec_命令
)这样的方法所做的。他们都在内部调用
Transport.open\u channel
。您可以根据需要调用所有这些,对于单个SSH会话。

我在这里嗅到-考虑解释我们,您试图实现的功能。我需要将我的连接与其他代理身份验证为另一级别的安全性,否则,无论我的私人钥匙匹配多少,由于中间人的原因,我都无法连接。从@martins的回答中——我明白我解决这个问题的方法是错误的……就是这样。我看不出
-S
与代理连接有什么关系。因此,我是否理解正确,即使是您选择的
-S
也没有根据?是的,从您的回答中,我得到了一个观点,即我对
scp
-S
感到困惑,并假设它存在于
ssh
中。。。。因为当我们需要
scp
时,我们需要
-S oursshbinary
,当我只需要在某个地方使用ssh时,我只需要运行
oursshbinary$server ls-al
——但我不明白如何使用
Paramiko
来实现这一点。(
oursshbinary
取代了已经实现代理/auth行为的本机linux
ssh
命令)您不能让Paramiko使用
oursshbinary
。您甚至不能让它使用
ssh
。Paramiko本身就是ssh。这是一样的(正如你现在知道的),好像你想要
ssh
使用
oursshbinary
(这没有意义)。你必须让帕拉米科做我们的家庭所做的事。但是我们不知道与ssh相比,
oursshbinary
做了什么。这是一个新问题,现在你知道该问什么了。