EOF when using pexpect and pxssh

£可爱£侵袭症+ 提交于 2019-11-29 14:16:45

Regarding #2: Expecting EOF is a red herring here. You -don't- expect EOF on login, you expect a password prompt on login. pxssh kicks that error when it gets back EOF on login from ssh without getting a password prompt. This can happen because it's using ssh -q to not get warnings, and you're getting a warning from ssh. Take the ssh options it is using and run them yourself without the q:

/usr/bin/ssh -l root 127.0.0.1

In my case, I can get this error message when ssh is kicking out a known hosts violation due to the machine I am connecting to having its identity changed.

ejm

I had the same error while trying to use self.expect() in pxssh. Changing the ssh options by removing the '-q' did not work for me.

I followed the instructions in this site by adding pexpect.EOF as one of the inputs to self.expect(). This will make the script wait till the entire string is received before exiting when EOF is received:

i = self.expect(["(?i)are you sure you want to continue connecting", original_prompt, "(?i)(?:password.*)|(?:passphrase for key)", "(?i)permission denied", "(?i)terminal type", pexpect.EOF, TIMEOUT, "(?i)connection closed by remote host"], timeout=login_timeout)

With this, it works fine !

yakamoz147

I know it's a long time since this question was asked but it just took me quite a while to figure it out and maybe I can help the next people running into this issue.

I found out, that the issue was caused by a Timeout. The method login() has an argument with default value login_timeout=10. If you set this higher at like 20 instead of 10 then the original script from the book works fine. The resulting line is:

s.login(host, user, password, login_timeout=20)

Maybe next I should try and find out why my ssh login is that slow...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!