-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"SSHException: Error reading SSH protocol banner" when using ProxyCommand #673
Comments
@depado I am having a similar issue connecting to Cisco devices through a proxy. In other words using ProxyCommand and I am receiving "SSHException: Error reading SSH protocol banner". Does it fix your problem if you do the following (to see if we are having the same issue): In transport.py line 486 add a short delay (this is using paramiko 1.16.0) # delay starting thread for SSH proxies
event.wait(0.2) # Added this delay
self.start() This fixes my issue. |
@ktbyers, I gave your solution a try but that doesn't seem to solve my problem. Thanks to pkapp on IRC I was able to debug a bit further what's going on. I started by activating the debug logs but paramiko isn't very chatty about what it does under the hood unfortunately. import logging
logging.basicConfig(level=logging.DEBUG) These are the only things paramiko sends me back before throwing the traceback at me.
I also learned that the cmd = "ssh {}@{} nc {} 22".format(host_cfg.get('user'), host_cfg.get('hostname'), destination_ip)
# cmd is now "ssh root@jump_ip nc dest_ip 22" where jump_ip and dest_ip are valid IPs
sock = ProxyCommand(cmd) Still getting the same error though, so it didn't come from there. I added a sock = ProxyCommand(cmd)
print(sock.process.poll())
print(sock.process.stdout.read())
print(sock.process.stderr.read()) This code yells the following output :
While the For those who wants more information, here is the line in paramiko that causes that error : transport.py:1858 (Thanks again pkapp for all the help on IRC o/) |
Able to reproduce under Python3 with a program that works find under Python2. Hacking around a bit with proxy.py to find out what the underlying issue really is. Will post findings if/when I can get some better details. |
Well we're getting to the bottom of this. Hope you can sort this out ! Thanks for all the help on IRC @radssh ! |
PR #681 submitted. With Python3 switch to io.BufferedReader, the select call here doesn't indicate that buffered data is ready to be read - only if new data has arrived. Changing to unbuffered pipes wound up breaking under Python2, since the method's own buffering code was a bit wonky to begin with. |
Very nice ! Thanks a lot @radssh ! |
I'm having an issue with the SSH banner as well. I'm using port forwarding in my ProxyCommand and paramiko doesn't seem to like it. Kills the connection with the same exception. The connection opens just fine and if I set the banner_timeout to a large value, I can connect to Is there any hope for me? |
We have a whole passle of other issues relating to this (common and often covering unrelated problems, YAY PROGRAMMING!) error, FTR. I don't have time right now to go dig them all up but if others want to do so & link them here, that'd be super appreciated. Would love to either merge some dusty PRs or otherwise have someone sleuth up a better way to surface these. |
@bitprophet, @radssh opened #681 |
@radssh +1 patch successful here too! But that's only for python 3.3 and 3.4 hence why the checks fails in the pull request, if i manage to cook a cross version compatible one i'll bring it back here |
Have just merged the related PR, will release momentarily (1.16+). |
Amazing, thanks :) |
For what it's worth, I've had increasing success increasing the banner_timeout when using a proxy, though I'm not 100% convinced that's the issue with this one, just wanted it written down for people also having this issue. 15 seconds is a long time, so I'm not sold, but ya, try increasing your banner_timeout. |
@ktbyers thank you for your help, your fix worked for me, I am using paramiko with corkscrew to tunnel out via squid proxy to a remote SFTP server and was facing this issue. But putting the time out before line 576 and 582 resolved my issue on transport.py |
* Attempt workaround for paramiko/paramiko#673 Add a delay and attempt to connect again when an SSHException occurs
I got a similar issue is a fix already in place?.. any workarounds? @ktbyers @abhiypathak what was the solution |
@bir87 If it is a network device increasing the banner_timeout will frequently help with this issue. |
@ktbyers I've been having a similar problem with ProxyCommand and trying to SSH into a cisco IOS device through a bastion host. It seems that no matter what I try I get a "Error reading SSH protocol banner" while trying to run an ansible playbook I cant get paramiko to honor the proxycommand / ssh configs. Running ssh -o ProxyCommand="ssh -W %h:%p @ -p " <device_username>@<device_ip> works just fine, but paramiko doesnt seem to be honoring any ssh.cfg settings or hostfiles ansible_ssh_common_args. |
@ktbyers I am also having this issue intermittently when connecting to cisco devices through a proxy i.e. a linux server to the device. I have increased the banner timeout to 100 yet i am still getting these errors intermittently |
@sreekaanth Yes, fix in Netmiko is almost always banner_timeout (in last year or so). If you are doing SSH proxy and banner timeout doesn't work, then I don't know the answer there. |
@ktbyers I am getting the same issue while trying to run an ansible playbook via a bastion server to csr cisco device. I am using ansible version 2.9.7 |
@vparames86 @ktbyers Same issue with ansible playbook, bastion and Juniper (PyEZ) |
@FloLaco Are you increasing the banner_timeout? |
@ktbyers My bad, I found my issue last night. The private key didn't have the proper chmod (400 vs 644) so connection fall in timeout. Unfortunately, the log message was not obvious (Error reading SSH protocol banner) for a simple timeout connection/issue with RSA key. |
Hi @FloLaco is playbook is executed can you please show how your host,proxy command and playbook looks like with some sample values.Actually I am not able to execute netwrok device through proxycommand.Thanks in advance. |
Playbook is basic, no changes here :
ansible.cfg :
.ssh/config :
Don't forget to put your private key (chmod 400). |
Hi @FloLaco thank you so much for the reply.. I have tried with above but still getting time out error. rpc_\nansible.module_utils.connection.ConnectionError: timed out\n", My doubt was is physical_eqt is junos device or any linux bastion server which is in subnet you mentioned in /.ssh/config can you please show how the host file looks like with some sample values. Thanks in advance. |
The host file is very basic. In the host file, you should have only network equipment. Ansible DOES NOT know any bastion and does not care. Ansible is using SSH application, which is configured to use a bastion :
group_vars/physical_eqt
You can try to set ANSIBLE_DEBUG=true and see the traceback to see what is the problem. |
Hi @FloLaco thanks for the reply... I have tried the same way but getting timeout error. .ssh/config : Host bastion Host xx.xx.xx.* [asa] group_vars/asa.ymlCREDENTIALS: Playbook:-
ansible.cfg : Can you please help if something is reqired or missing something. Thanks in advance. |
Did you try to set ANSIBLE_DEBUG=true and -vvvv and see what's going on ? |
Hello,
It's been a few days and I'm still struggling with this, I think it's quite a known issue but wasn't able to find a workaround.
Below is a simplified version of my actual code that throws the same error :
Note that the whole parsing the ssh config thing is simplified because I know this entry is in the ssh config. (And yes I'm sure the error doesn't come from that because the generated ProxyCommand is correct)
Of course it raises the error when executing the
client.connect
line. The ProxyCommand is correct, tested multiple times and works just fine in my~/.ssh/config
. When using it with the command line, it creates an entry in the logs of my bastion. When using it within paramiko it doesn't generate an entry in the logs.I also tested using the
netcat
approach like this :This time it generates an entry in the logs of my bastion (even though it still raises this error) but closes the connection immediatly.
Anyone having the same issue and could help me with that ?
The text was updated successfully, but these errors were encountered: