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參數