Solved Closing cu from within an ssh session?


Active Member

Reaction score: 1
Messages: 110

host_a is local
host_b is remote

host_a connects to host_b via ssh

host_b has a serial line to a network device on /dev/cuau0

From host_a, through my ssh session, I can use cu--> cuau0 --> network device.

cu -l /dev/cuau0 -s 9600

Everything works as expected/intended up to this point.

But then, if I want to close down the serial connection without closing my ssh session... fail.
I need to be able to shut down and exit out of the cu session on cuau0, during the ssh session I opened it from.

The normal way to close down cu to cuau0 is keystroke " ~." or " ~^d", the " ~" is an escape signal, followed by a command. Which, gets a bit tricky at times. Sometimes it registers a literal " ~" character, other times it registers as an escape signal. Hitting the esc key a bunch of times followed by a quick " shift+~" will do it.
But, if I do it while ssh'd to host_b it closes the ssh session.

There's also " ~!"
If I use " ~!" it drops me back into my ssh session, but the lock is still in place. And if someone else tries to access the port it's busy.
I need to close down cu properly, within the original ssh session I opened it from.

Maybe I'm missing somethign simple?

What is the proper way to shutdown and exit out of a cu session?

and what is the proper way to do it from within an ssh session?


Staff member

Reaction score: 3,631
Messages: 13,850

Re: Closing cu from within an ssh session?

Untested, but ssh(1) allows changing the escape character. So ssh -e % hostb should let the ~. get through to cu(1).



Reaction score: 932
Messages: 1,492

Re: Closing cu from within an ssh session?

Your problem is that both cu and ssh use the same escape character, namely tilde or "~".

Option 1: Change the escape character that cu uses. It's the variable "escape" in the cu configuration file. It may take some effort to find another rarely-used character, like backslash or vertical bar or backquote.

Option 2: Change the escape character that ssh uses. That's easier, use option -e on the ssh command line. Again, there aren't terribly many possible choices.

Option 3: I think there is a signal that you can send to cu to make it quit. But to be honest, I don't remember which signal that is, and the documentation is silent on it. Open a second window to the same host, and use the kill command in the second window. You may have to experiment with what signal to send (common candidates are QUIT, KILL, TERM, USR1). If all else fails, google for hints, or read the source to cu. There is some danger that cu is willing to absorb certain signals without quitting, or that it will crash uncleanly (perhaps leaving the serial port in a messed-up state, or leaving log files not updated).


Active Member

Reaction score: 1
Messages: 110

Re: Closing cu from within an ssh session?

Great advice! and greatly appreciated.

I didn't want to change from the default, but adding a switch to the initial opening of the port is an appropriate compromise.

Locally, cu has several different options for manipulating the session, but its also used to access devices, which, as you hinted at, require a wide range of keys...

Now to find the perfect alternative escape key!


New Member

Messages: 1

Try this, it works for me: ~~.
I'm not 100% certain on the reason, but I think that it works because SSH only sees the first ~, but ~~ isn't a command so it passes the second one through.