Description
Bug report
Using libssh2
examples, I tried opening shell inside a channel in ssh2-python
and it failed. I need to have a channel and a shell kept open for re-use. I cannot use exec
because using exec
to run a command closes the channel (which is expected).
Here is an example in the tests of libssh2
:
https://github.com/libssh2/libssh2/blob/master/tests/ssh2.c#L152
libssh2_channel_shell
is a macro:
https://github.com/libssh2/libssh2/blob/master/include/libssh2.h#L775
I get a LIBSSH2_ERROR_SOCKET_DISCONNECT
error code (-13
) when trying to open the shell.
https://github.com/libssh2/libssh2/blob/master/include/libssh2.h#L451
Steps to reproduce:
Run the SSH daemon locally and add an SSH public key to the authorized_hosts
file of any user (here root
)
Run the following Python script.
#!/usr/bin/env python
import socket
from ssh2.session import Session
from ssh2.utils import version
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("localhost", 22))
session = Session()
session.handshake(sock)
session.userauth_publickey_fromfile(
"root", "/root/.ssh/id_rsa.pub", "/root/.ssh/id_rsa", ""
)
channel = session.open_session()
print("pty")
err_code = channel.pty()
print(err_code)
print("shell")
err_code = channel.process_startup("shell", "")
print(err_code)
channel.close()
pty
0
shell
-13
Expected behaviour: 0 error code on shell request
Actual behaviour: error on shell request
Additional info:
libssh2-1:amd64 1.5.0-2ubuntu0.1
libssh2-1-dev:amd64 1.5.0-2ubuntu0.1
python-libssh2 1.0.0-1.2