我使用Python的paramiko包连接到远程Unix机器。我写了这段代码:
import paramiko
import sys
import os
import os.path
passwd = "XXX"
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("173.15.13.28", "root", password=passwd)
stdin, stdout, stderr = ssh.exec_command('ls')
x = stdout.readlines()
print x
for line in x:
print line
ssh.close()
执行后我收到此错误:
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
ssh.connect("173.15.13.28", "root", password="--------")
File "C:\Python27\lib\site-packages\paramiko\client.py", line 282, in connect
for (family, socktype, proto, canonname, sockaddr) in socket.getaddrinfo(hostname, port,socket.AF_UNSPEC, socket.SOCK_STREAM):
gaierror: [Errno 10109] getaddrinfo failed
我不知道问题是什么。
答案 0 :(得分:6)
connect()方法的第二个参数是端口号,默认为22.你在那里放“root”,这是行不通的。使用关键字参数username="root"
。也就是说,试试这个:
ssh.connect("173.15.13.28", username="root", password=passwd)
另请参阅:python paramiko, getaddrinfo error when trying to establish an SSH connection