You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to build a little terminal application with golang.org/x/term. Until now I only had one terminal which was started when I ran ssh user@localhost. But if SSH is given a command while starting the connection, the terminals no longer work (terminal.ReadLine() and .ReadPassword("...") never return and don't react to newlines).
This is a minimal example to reproduce this:
package main
import (
"io""github.com/gliderlabs/ssh""golang.org/x/term"
)
funcmain() {
handler:=func(s ssh.Session) {
term:=term.NewTerminal(s, "Enter your name: ")
line, err:=term.ReadLine()
iferr!=nil {
panic(err)
}
io.WriteString(s, "Your name is: "+line+"\n")
}
server:= ssh.Server{
Addr: ":2222",
Handler: handler,
}
server.SetOption(ssh.HostKeyFile("./id_ed25519"))
panic(server.ListenAndServe())
}
When I run ssh user@localhost -p 2222, it works:
But when a append any command to SSH nothing happens at ReadLine(), no matter how often I press Enter: However, my input is somehow "reflected" into the SSH window, which is not the case without the command (maybe this is the reason, why ReadLine() never returns?):
Just found out that it works with ssh user@localhost -tt -p 2222 some-command. Is there any way to accomplish this in the backend implementation? Or is this a limitation of the SSH client?
As per the ssh man page, a pty will only be requested for an interactive session by default. When a command is supplied, it is executed in a non-interactive session.
A pty has a client and a server side, so both your client needs to request the pty and the server needs to accept the request (this library does by default). So no, there is no way for a server to force a client to use a pty.
This video might help visualise exactly what is being emulated by the pty.
I'm trying to build a little terminal application with golang.org/x/term. Until now I only had one terminal which was started when I ran
ssh user@localhost
. But if SSH is given a command while starting the connection, the terminals no longer work (terminal.ReadLine()
and.ReadPassword("...")
never return and don't react to newlines).This is a minimal example to reproduce this:
When I run
ssh user@localhost -p 2222
, it works:But when a append any command to SSH nothing happens at
ReadLine()
, no matter how often I press Enter: However, my input is somehow "reflected" into the SSH window, which is not the case without the command (maybe this is the reason, whyReadLine()
never returns?):This is my
go.mod
if required:I tried debugging this for some time now, but I don't get why this is not working. Any ideas how to fix this? Or is this a bug?
The text was updated successfully, but these errors were encountered: