Skip to content

Serve interactive shells from the SSH server - #24

Merged
plajjan merged 2 commits into
mainfrom
server-shell
Nov 10, 2026
Merged

plajjan merged 2 commits into
mainfrom
server-shell

Conversation

@plajjan

@plajjan plajjan commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

ServerSession handled only exec and subsystem channel requests and refused the rest. A client that opens a shell sends pty-req first, so Channel.request_shell() against an ssh.Server failed with "Failed to request PTY". A test server could not stand in for a device that a client drives through a shell, like IOS XE, where the StratoWeave CLI adapter keeps one shell open per device.

Server gets an optional on_shell(session, channel, pty). When it is set, the server accepts pty-req and gives the terminal to on_shell with the shell request: a PtyRequest with term, cols, rows, width_px and height_px, or None when the client asked for no terminal. The application accepts or rejects the shell as for exec. Without on_shell the server refuses both requests, as before. on_shell comes after on_session_close in the Server parameters, so callers that give on_session_close by position keep working.

The second commit adds terminal size changes. ServerChannel gets an optional on_window_change(channel, cols, rows), and Channel gets change_pty_size(cols, rows) to send one. The client sends it once the shell runs, because libssh sends window-change as a channel request, and that would take the reply of a shell request still in flight.

The new loopback tests open a shell with and without a terminal, check that a server without on_shell refuses it, close the channel in the middle of a command, and change the terminal size. The full suite, the write-barrier checker run and the OpenSSH interop tests pass.

ServerSession handled only exec and subsystem channel requests and refused
every other one. A client that opens a shell sends pty-req first, so
Channel.request_shell() against an ssh.Server failed with "Failed to
request PTY".

Server gets an on_shell callback. When it is set, the server accepts
pty-req, keeps the terminal on the channel, and gives it to
on_shell(session, channel, pty) with the shell request. pty is a
PtyRequest with term, cols, rows, width_px and height_px, or None when the
client asked for no terminal. The application accepts or rejects the
shell request as for exec. Without on_shell the server refuses both
requests, as before.

on_shell comes after on_session_close in the Server parameters, so callers
that give on_session_close by position keep working.
A client sends window-change when the terminal of its shell changes size.
The server refused it, and the client had no way to send one.

ServerChannel gets an optional on_window_change(channel, cols, rows). The
server gives each window-change to it, also while another request on the
channel waits for the application. The client wants no reply.

Channel gets change_pty_size(cols, rows). libssh sends window-change as a
channel request, which waits for the reply of a request still in flight,
so the client sends it once the shell runs. On a shell without a terminal
it sends nothing.
@plajjan
plajjan merged commit 27934c2 into main Nov 10, 2026
1 check passed
@plajjan
plajjan deleted the server-shell branch November 10, 2026 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant