Failed to use asyncssh with windows vm server

15 views
Skip to first unread message

reut kahan

unread,
May 19, 2020, 3:03:52 AM5/19/20
to asyncssh-users

Hello,

We successfully use asyncssh library in order to access linux servers in our python project.

We tried to access windows vm and got the following error:

“SSH connection failed: Session request failed.”

 

This is the part in code that failed:

 

conn, conn_client = await asyncssh.create_connection(SSHClient, **create_conn_params)
 stdin, stdout, stderr = await conn.open_session()”

 

Failed with python 3.5 and 3.7 as well , asyncsh version – 2.2.1.

 

Can somebody advise please?

 

Thanks in advance,

Reut.

Ron Frederick

unread,
May 19, 2020, 10:32:39 AM5/19/20
to reut kahan, asyncssh-users
This means that the SSH server you are trying to connect to returned an error when AsyncSSH made a request to open a session. Unfortunately, the SSH protocol doesn’t allow for a more detailed error message to be sent back on this kind of failure. So, you’ll need to check the logs on the server to see what the Windows SSH server rejected the request.

It looks like you were trying to open an interactive shell. If you try passing in a command to the open_session() call, do you still see a failure? That would make a different kind of session request (‘exec’ vs. ’shell’).

Are you running the Windows 10 SSH server provided by Microsoft, or something else? Can you successfully log into this server using another SSH client such as OpenSSH?

As an aside, AsyncSSH 2.0 and later only supports Python 3.6 and later. Python 3.5 is no longer officially supported, though I don’t think that has anything to do with the problem you’re seeing here.
-- 
Ron Frederick
ro...@timeheart.net



reut robinson

unread,
May 27, 2020, 4:22:55 AM5/27/20
to Ron Frederick, asyncssh-users
Thank you for your answer.
1. The command i passed to open_session is "systeminfo" and not open shell. jsut regular command that should return test output.
2. I'm running windows 2012 server:
OS Name:                   Microsoft Windows Server 2012 R2 DataCenter
OS Version:                6.3.9600 N/A Build 9600
3. Yes , i can log in to this server using other ssh client.

In python 3.5 we use older asyncssh version i just wanted to mention that it doesn't work in python 3.6 and latest asyncssh as well.

I reviewed sshd logs in the server and didn't saw any problem.

Attaching the log.

‫בתאריך יום ג׳, 19 במאי 2020 ב-17:32 מאת ‪Ron Frederick‬‏ <‪ro...@timeheart.net‬‏>:‬
sshd.log

Ron Frederick

unread,
May 27, 2020, 9:55:50 AM5/27/20
to reut robinson, asyncssh-users
There’s no sign in the log here of you passing in the command “systeminfo”. In fact, it appears to be trying to start an interactive shell:

980 2020-05-27 09:35:05.189 debug1: server_input_channel_req: channel 0 request shell reply 1
980 2020-05-27 09:35:05.189 debug1: session_by_channel: session 0 channel 0
980 2020-05-27 09:35:05.189 debug1: session_input_channel_req: session 0 req shell
980 2020-05-27 09:35:05.189 Starting session: shell for administrator from 10.55.136.25 port 35686 id 0
980 2020-05-27 09:35:05.189 debug2: fd 9 setting O_NONBLOCK
980 2020-05-27 09:35:05.189 debug2: fd 10 setting O_NONBLOCK
980 2020-05-27 09:35:05.189 debug2: fd 11 setting O_NONBLOCK
980 2020-05-27 09:35:05.189 debug2: fd 12 setting O_NONBLOCK
980 2020-05-27 09:35:05.189 debug2: fd 13 setting O_NONBLOCK
980 2020-05-27 09:35:05.189 debug2: fd 14 setting O_NONBLOCK
980 2020-05-27 09:35:05.189 debug3: shell: "c:\\windows\\system32\\cmd.exe"
980 2020-05-27 09:35:05.189 debug3: shell_option: /c
980 2020-05-27 09:35:05.189 debug3: exec_command: (null)

If you are calling "stdin, stdout, stderr = await conn.open_session()", it would make sense that it would be requesting a shell and not trying to execute a command, as the open_session() call takes the command to run as an optional argument. By not specifying a command there, it defaults to requesting a shell. Can you share a more complete version of the code calling AsyncSSH?

Immediately after this, the log shows:

980 2020-05-27 09:35:05.189 debug3: send packet: type 100

This is MSG_CHANNEL_FAILURE, which explains why AsyncSSH is reporting that it got an error opening the session. After that, the log shows the usual cleanup as the connection is being shut down.

One other thing I notice is that you appear to be attempting to start a shell as “administrator”. Could there be a permissions issue where Windows is not allowing SSH to do that? When you tested opening a session with a regular SSH client, were you attempting to log in as “administrator”?

The other thing I notice is that it is running cmd.exe with he “/c” option, which says to carry out the command and then stop.However, there is no command here, so perhaps that’s the reason for the failure.

If you change your call to "stdin, stdout, stderr = await conn.open_session(’systeminfo’)", does that change anything?

I’d also suggest comparing the server logs between the AsyncSSH case and the working case to see what differences are present.
Reply all
Reply to author
Forward
0 new messages