Interactive SSH client with golang.org/x/crypto/ssh - problems with control codes

1,491 views
Skip to first unread message

Daniel Bryan

unread,
Mar 7, 2015, 9:53:24 PM3/7/15
to golan...@googlegroups.com
Hi all,

I'm working on a program that sometimes drops the user into an interactive shell on a remote host, via SSH.

I decided to use the excellent Go crypto/ssh library to implement this natively instead of shelling out to OpenSSH, for simplicity and portability.

Unfortunately I'm having trouble getting various interactive shell features to work correctly. The problems fall into two groups:
  • signal handling
  • control codes for tab completion, cursor navigation, etc.

I'm confident that I can figure out the signal handling with the interface presented by the package and experimentation, but the control code problem really has me stumped.

I've put up a detailed question on Stack Overflow outlining my problem including the sample code from my program (basically cookie-cutter crypto/ssh usage): http://stackoverflow.com/questions/28921409/how-can-i-send-terminal-escape-sequences-through-ssh-with-go

Basically: I drop a shell by creating a Session whose stdin, stderr and stdout are that of my main process, call RequestPty(), Shell() and Wait(). The shell works well enough, but if the user presses (for example) left arrow, I see the escape code for it show up in the console (^[[A).

Someone in #golang-nuts quite helpfully suggested that I re-read The TTY Demystified, which I did, but I still can't figure out what is going on or how to prevent it.

The crypto/ssh/terminal package looks like it should be important for solving my problem, but I can't actually see how.

I'm not even sure precisely whether #golang-nuts is the write place to ask this question, but there's a simple reason why I need to solve it in terms of Go: if I was working in various other languages, I can't experiment with how a fork() would affect with the signal and TTY handling.

I can't solve the (hopefully simpler) problems with signal handling until this is sorted out, because when I hit ^c I can't tell whether the acknowledgement of it is being printed by my terminal or the one on the remote host.

I'd appreciate any pointers whatsoever. I'm about on the verge of pulling down my UNIX Programming tome from the bookshelf, but can't be confident I'm not doing something silly specifically related to (or unsupported by) Go.

brik...@gmail.com

unread,
May 4, 2016, 8:46:26 PM5/4/16
to golang-nuts
Sorry to dig up an old thread, but did you ever get this working?

I'm having the exact same issues: 

1. Signal handling. Although I can use go's signal.Notify to capture SIGINT (CTRL+C), I can't find a way to forward it to my SSH session. When I call session.signal(ssh.SIGINT), nothing seems to happen (e.g. whatever was running keeps running).
2. Control codes. Even with ssh.ECHO and ssh.ECHOCTL set to 0 in the TerminalModes, I still don't have tab completion, cursor navigation, etc.

Any ideas?
Reply all
Reply to author
Forward
0 new messages