无法使用Windows中的Paramiko登录Linux服务器

时间:2016-03-28 12:48:04

标签: python linux ssh paramiko

您好我通过远程桌面使用Windows Server 2008 R2。

我的要求是登录Linux计算机并将软件包复制到Windows Server 2008计算机。

但是在第一阶段我只是被卡住了,无法登录Linux服务器。 我在远程桌面上编写了以下代码。

def Package_Copying(self,timeout=60):

    ssh=paramiko.SSHClient()

    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    ssh.connect("10.82.110.9",timeout=70,username='XXXX',password='XXXXX',look_for_keys=False)



    ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command('ls -ltr')

    print "output",  ssh_stdout.read() 

    self.close()

当我执行相同操作时,我收到以下错误。

"error: (10060, 'A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond')"

当我从putty做同样的事情时,我能够登录。但登录需要3或4秒。

以下是同一服务器的Ping跟踪

C:\Users\Administrator>ping 10.82.110.9

Pinging 10.82.110.9 with 32 bytes of data:

Reply from 10.82.110.9: bytes=32 time=229ms TTL=234

Reply from 10.82.110.9: bytes=32 time=229ms TTL=234

Reply from 10.82.110.9: bytes=32 time=230ms TTL=234

Reply from 10.82.110.9: bytes=32 time=229ms TTL=234


Ping statistics for 10.82.110.9:

    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

    Minimum = 229ms, Maximum = 230ms, Average = 229ms


C:\Users\Administrator>

1 个答案:

答案 0 :(得分:0)

我在paramiko中设置了错误的端口时遇到了类似的错误,尝试添加端口标志:

 ssh.connect("10.82.110.9",port=22,timeout=70,username='XXXX',password='XXXXX',look_for_keys=False)