python paramiko 各种错误

Error reading SSH protocol banner

 

这个错误出现在服务器接受连接但是ssh守护进程没有及时响应的情况(默认是15s).

要解决这个问题, 需要将paramiko的响应等待时间调长。

transport.py中def __init__()初始化函数中:
					
					

# how long (seconds) to wait for the SSH banner
self.banner_timeout = 15

 

client.py中

def connect(
self,
hostname,
port=SSH_PORT,
username=None,
password=None,
pkey=None,
key_filename=None,
timeout=None,
allow_agent=True,
look_for_keys=True,
compress=False,
sock=None,
gss_auth=False,
gss_kex=False,
gss_deleg_creds=True,
gss_host=None,
banner_timeout=None,
auth_timeout=None,
gss_trust_dns=True,
passphrase=None,
disabled_algorithms=None,
):

t = self._transport = Transport(
sock,
gss_kex=gss_kex,
gss_deleg_creds=gss_deleg_creds,
disabled_algorithms=disabled_algorithms,
)

 

if banner_timeout is not None:
t.banner_timeout = banner_timeout

 

解决方案

ssh = paramiko.SSHClient() #创建一个ssh对象
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) #选择yes,接受key
ssh.connect(ip, int(port), username, password, banner_timeout=300,timeout=5) #连接服务器,加上banner_timeout参数

 


				
 

猜你喜欢

转载自www.cnblogs.com/jeancheng/p/13369493.html