Paramiko Error: Error reading SSH protocol banner

Asked
Active3 hr before
Viewed126 times

7 Answers

error
90%

25 This happens if the server accepts the connection but the ssh daemon doesn't respond within 15 seconds. It could be network congestion, faulty switches, etc... but usually it means that the target server is bogged down or its sshd has hung. Recovery is to wait and try again. If you control the server, its a good time to check on its health. – tdelaney Sep 1 '14 at 16:49 ,This is strange because it happens randomly on any connections. Is there any way to fix it ?, 1 You can reproduce this error by making 10 threads and opening/closing sftp connections as fast as you can on all of them. The sshd daemon can't respond in time, and the above exception is thrown. – Eric Leschinski Jan 15 '15 at 20:21 ,Recently, I made a code that connect to work station with different usernames (thanks to a private key) based on paramiko.

Since Paramiko v. 1.15.0, released in 2015, (this PR, to be precise) you can configure that value when creating Paramiko connection, like this:

client = SSHClient()
client.connect('ssh.example.com', banner_timeout = 200)
load more v
88%

What to put in your bug report,The python, with important part at bottom:,It looks like it might be worth passing banner_timeout to Connection.connect_kwargs and seeing if that helps.

for name in instanceNames:
   print(f '\nChecking {name} ...')
c = Connection(name)
try:
print('Exec hostname')
r = c.run('hostname', warn = True)
print(f '{r}')
except:
   print('SSH session error')
load more v
72%

Recently, SFTP upload and download should be configured in the project. After the environment is configured, the connection will report an error.,[Solved] Go use zoom to connect DM database and start reporting error in Linux,Pay attention to check your host, port, username, password and other information, as well as upload or download directory path!,Using common file upload to upload files in SSH project

The error information is as follows:

paramiko.ssh_exception.SSHException: Error reading SSH protocol banner
load more v
65%

That error is generated when paramiko doesn't receive a protocol banner, or the server sends something invalid. If the server is otherwise working correctly, this may be due to some network restrictions.,I can connect to my server from the terminal. This thread didn't help since our scenario is different. ,I am using Paramiko and trying to connect to my SFTP server. Here is the code I wrote:,You can use -vvv as an option to the openssh client to get more information about how it's connecting, and you can get the actual banner easily using netcat or telnet on port 22. The banner should start with 'SSH-', or paramiko will return the above error immediately.

I am using Paramiko and trying to connect to my SFTP server. Here is the code I wrote:

class SFTPUploader:
   def __init__(self, host, username, password, port):
   transport = paramiko.Transport((host, port))
print transport
transport.connect(username = username, password = password)
self.sftp = paramiko.SFTPClient.from_transport(transport)
75%

That error is generated when paramiko doesn't receive a protocol banner, or the server sends something invalid. If the server is otherwise working correctly, this may be due to some network restrictions.,Doing some research on this, I have come to the conclusion that public key auth by a Paramiko SSH client doesn't always work with all SSH servers. I was trying to connect to a Cisco ASA device. The relevant part of the error log was:,Recently, I made a code that connect to work station with different usernames (thanks to a private key) based on paramiko.,I don't know if this is a paramiko bug or a bug on the SSH server. Paramiko does fall back from publickey to password or keyboard-interactive when talking to an OpenSSH server.

Python has lots of ways to perform string formatting. One of the simplest is to simply concatenate the parts of your string together:

#!/usr/bin/env python

hostname = '192.168.3.4'
port = 22
username = 'username'
password = 'mypassword'
y = "2012"
m = "02"
d = "27"

def do_it():
   s = paramiko.SSHClient()
s.load_system_host_keys()
s.connect(hostname, port, username, password)
command = 'ls /home/user/images/cappi/03000/' + y + '/' + m + '/' + d(stdin, stdout, stderr) = s.exec_command(command)
for line in stdout.readlines():
   print line
s.close()

if __name__ == "main":
   do_it()
load more v
40%

if the socket is open, but the responding service is not SSH, then Paramiko emits paramiko.ssh_exception.SSHException with a particular message Error reading SSH protocol banner,if the socket is open and SSH service responding on the remote part - we are good to go! This time still paramiko.ssh_exception.SSHException is emitted, but the error message would be No authentication methods provided.,if there is nothing listening on a particular socket, then Paramiko emits paramiko.ssh_exception.NoValidConnectionsError,I found it sufficient to setup a timer-driven while loop where Paramiko tries to open a connection without credentials. In order to detect if socket is opened I catch different type of exceptions that Paramiko emits:

Today I faced a task which required first to establish an SSH tunnel in a background process and later use this tunnel for SSH connection. What seemed like a child’s play first actually had some fun inside.

A problem were hidden right between the moment you spawned ssh process in the background and the next moment you tried to use this tunnel. In other words, it takes literally no time to spawn a process in the background, but without checking that tunnel is ready, you will quite likely receive an error, since your next instructions will be executed immediately after.

ssh
load more v
22%

A note to anyone seeing this currently. "Error reading SSH protocol banner" is kind of a catch-all error for paramiko so the causes can be various. In my case the actual, underlying error was the following.,See more:http://pulpito.ovh.sepia.ceph.com:8081/teuthology-2016-01-28_05:00:01-smoke-master-distro-basic-openstack/,[1] https://wiki.sepia.ceph.com/doku.php?id=testnodeaccess#sshexceptionerror_reading_ssh_protocol_banner,Run: http://pulpito.ovh.sepia.ceph.com:8081/teuthology-2016-01-23_02:00:01-rados-infernalis-distro-basic-openstack/Jobs: allLogs: http://teuthology.ovh.sepia.ceph.com/teuthology/teuthology-2016-01-23_02:00:01-rados-infernalis-distro-basic-openstack/8006/teuthology.log

2016 - 01 - 23 T02: 57: 22.835 INFO: teuthology.misc: Re - opening connections...
   2016 - 01 - 23 T02: 57: 22.835 INFO: teuthology.misc: trying to connect to ubuntu @target085224.ovh.sepia.ceph.com
2016 - 01 - 23 T02: 57: 22.837 DEBUG: teuthology.orchestra.connection: {
   'username': 'ubuntu',
   'hostname': 'target085224.ovh.sepia.ceph.com',
   'key_filename': '/home/teuthworker/.ssh/id_rsa',
   'timeout': 60
}
2016 - 01 - 23 T02: 57: 23.402 ERROR: paramiko.transport: Exception: Error reading SSH protocol banner[Errno 104] Connection reset by peer
2016 - 01 - 23 T02: 57: 23.403 ERROR: paramiko.transport: Traceback(most recent call last):
   2016 - 01 - 23 T02: 57: 23.404 ERROR: paramiko.transport: File "/home/teuthworker/src/teuthology_master/virtualenv/local/lib/python2.7/site-packages/paramiko/transport.py", line 1516, in run
2016 - 01 - 23 T02: 57: 23.404 ERROR: paramiko.transport: self._check_banner()
2016 - 01 - 23 T02: 57: 23.404 ERROR: paramiko.transport: File "/home/teuthworker/src/teuthology_master/virtualenv/local/lib/python2.7/site-packages/paramiko/transport.py", line 1633, in _check_banner
2016 - 01 - 23 T02: 57: 23.404 ERROR: paramiko.transport: raise SSHException('Error reading SSH protocol banner' + str(x))
2016 - 01 - 23 T02: 57: 23.405 ERROR: paramiko.transport: SSHException: Error reading SSH protocol banner[Errno 104] Connection reset by peer
2016 - 01 - 23 T02: 57: 23.405 ERROR: paramiko.transport:
   2016 - 01 - 23 T02: 57: 23.426 DEBUG: teuthology.orchestra.remote: Error reading SSH protocol banner[Errno 104] Connection reset by peer
load more v

Other "error-undefined" queries related to "Paramiko Error: Error reading SSH protocol banner"