News for hackers. Stuff that matters.
Re:What typing ^D does on Unix (2009) by SteveNuts on Tuesday September 06, 2016 @02:01PM (#12437932)
Pressing enter then ~. will gracefully shutdown hung ssh sessions
Re:What typing ^D does on Unix (2009) by grive on Tuesday September 06, 2016 @02:50PM (#12438319)
More generally, type ~ as an escape sequence.

For example, type ~^Z to put a session in the background.

Similarly, type ~~ to send an escape sequence in an inner session, etc...

Re:What typing ^D does on Unix (2009) by qwertyuiop924 on Tuesday September 06, 2016 @04:09PM (#12438941)
...

  There's a program called SSH to get to another CPU.
  Tilde is the escape, it's doubled to send it through,
  And "quit" is tilde-.
I think you know how the rest goes...
Re:What typing ^D does on Unix (2009) by scubbojj on Tuesday September 06, 2016 @09:41PM (#12440483)
I don't - and in fact I finally got around to creating a HN account in order to ask you. Googling that just leads me back to this discussion. What's it from?
Re:What typing ^D does on Unix (2009) by qwertyuiop924 on Wednesday September 07, 2016 @06:33AM (#12442139)
It's parodying "the TELNET song," by Guy L. Steele.
Re:What typing ^D does on Unix (2009) by nandhp on Saturday September 10, 2016 @12:11AM (#12467654)
For more information: http://wonderingminstrels.blogspot.com/2004/01/telnet-song-g...

If you have an ACM subscription, the sheet music was published in Communications of the ACM (Volume 27, Issue 4; April 1984): http://dl.acm.org/citation.cfm?id=1035691

Re:What typing ^D does on Unix (2009) by likeclockwork on Tuesday September 06, 2016 @09:30PM (#12440453)
What does this reference?
Re:What typing ^D does on Unix (2009) by qwertyuiop924 on Wednesday September 07, 2016 @06:36AM (#12442145)
It references "The TELNET Song" by Guy L. Steele (a.k.a The Great Quux). The original is about Telnet, and given the subject of discussion, the reference seemed a natural one to make.
Re:What typing ^D does on Unix (2009) by lake99 on Wednesday September 07, 2016 @03:57AM (#12441535)
I am not sure, but it looks vaguely familiar. There is a text-based game called adventure game called Dunnet where you come across a CPU card, and do some stuff with it later on. As far as I remember, the game predates SSH, so the game either had Telnet or FTP. My memory fades.
Re:What typing ^D does on Unix (2009) by voidz on Tuesday September 06, 2016 @08:51PM (#12440314)
Or type ~? for a list of escapes.
Re:What typing ^D does on Unix (2009) by zingermc on Tuesday September 06, 2016 @02:39PM (#12438249)
I am amazed by the fact that I never accidentally trigger this feature.
Re:What typing ^D does on Unix (2009) by smhenderson on Tuesday September 06, 2016 @03:27PM (#12438628)
Hah, yeah I seem to remember Ctrl-S leaving me flustered for quite a while when I first stumbled on it!
Re:What typing ^D does on Unix (2009) by gonvaled on Tuesday September 06, 2016 @04:33PM (#12439100)
^-Q is your friend!
Re:What typing ^D does on Unix (2009) by makomk on Tuesday September 06, 2016 @07:22PM (#12439969)
You'd probably trigger it more often if ~/ didn't conveniently map to ~/ - it's quite cleverly designed in a way. Indeed, most of the two-character combinations you're likely to type starting with ~ map to themselves.
Re:What typing ^D does on Unix (2009) by knorker on Tuesday September 06, 2016 @08:59PM (#12440344)
It's annoying when you're adminning users and atually want to type "~user/foo" though.
Re:What typing ^D does on Unix (2009) by syncsynchalt on Tuesday September 06, 2016 @03:31PM (#12438659)
Yes, it's a good choice of characters.

Specifically, the escape sequence is "\n~", with various options (visible by typing "\n~?"), and if the option is unknown it passes the "\n~{x}" as-is.

The biggest false positive you'll see is "\n~v", when executing bins out of the home dir of a user starting with the letter 'v'.

Re:What typing ^D does on Unix (2009) by ChuckMcM on Tuesday September 06, 2016 @02:40PM (#12438254)
Sadly it will shutdown only the 'outer' ssh session, so if you ssh to foo, and then from foo ssh to bar, and type ~. then the client->foo session is shut down but the foo->bar session is still around.
Re:What typing ^D does on Unix (2009) by grive on Tuesday September 06, 2016 @02:46PM (#12438285)
You need to type one ~ per session level toy want to reach and terminate. In your example, type ~~. to terminate the inner session, leaving the outer one live.
Re:What typing ^D does on Unix (2009) by Canada on Tuesday September 06, 2016 @02:48PM (#12438302)
To kill the inner one you need to escape it: ~~. ~? displays the supported escape sequences.
Re:What typing ^D does on Unix (2009) by alfanick on Tuesday September 06, 2016 @02:02PM (#12437949)
nice one, never seen that - always used ^D/exit
Re:What typing ^D does on Unix (2009) by wyldfire on Tuesday September 06, 2016 @02:09PM (#12437988)
Those are yet more graceful -- for when the shell is responsive. Use ~. in cases where for some reason you cannot get access to the terminal anymore but remote sshd is responsive.
Re:What typing ^D does on Unix (2009) by 0x0 on Tuesday September 06, 2016 @02:23PM (#12438094)
Actually the remote sshd does not need to be responsive, because "<cr>~." is interpreted by the local ssh client. Very convenient if the TCP connection is stuck.

You can also type "<cr>~?" for a list of other commands supported by the local ssh client. Among other things, "<cr>~C" opens a command line interpreter on the client side of the ssh client, allowing you to add and remove TCP port forwarding without restarting the connection.

Re:What typing ^D does on Unix (2009) by Tyr42 on Tuesday September 06, 2016 @04:20PM (#12439015)
Ahg, I wish it let you scp files into your working directory too. That's be convenient.
Re:What typing ^D does on Unix (2009) by thomashabets2 on Tuesday September 06, 2016 @09:09PM (#12440379)
Long ago I sent a patch for uploading downloading using this escape sequence, using zmodem like how an old windows SSH client (I forget the name) used to allow uploading/downloading files.

You log in, type "rz<enter>", and then use escape sequence to upload a file. (similar for downloading)

The patch was rejected. Shame. It's very useful when hopping 6 steps to upload a file.[1]

I can't find the patch now, but I'm considering rewriting it as a an `expect` script. My `expect` scripts tend to have trouble with SIGWINCH propagation though, so not optimal. Also you have to remember to wrap with the `expect` script at (and preferably only at) the one "jump" you want to send from/to with the final destination.

[1] No, nothing illegal. Just that some networks mandate SSH jumpgates, and sometimes multi-level.

Re:What typing ^D does on Unix (2009) by aji on Tuesday September 06, 2016 @02:18PM (#12438046)
~. (and the other ~ commands) are handled locally, not by the remote sshd. I use it when my network cuts out or something and my ssh session is unrecoverably stuck
Re:What typing ^D does on Unix (2009) by russb on Tuesday September 06, 2016 @02:32PM (#12438179)
You can also layer the number of ~'s to skip over intermediary SSH sessions and send the escape to the proper one.

\n~~. will escape the 2nd box you've SSH'd to, not the one it was originated from.

Useful for escaping a screen'd SSH session that you might access through a jumphost.

Re:What typing ^D does on Unix (2009) by abstractbeliefs on Tuesday September 06, 2016 @02:17PM (#12438039)
iirc, enter-~-. isn't anything to do with the remote sshd. Instead, it escapes to the local ssh client (enter-~) that it should close (.). Which is really useful for if the remote sshd blew up, or, more commonly, your connection was broken.