News for hackers. Stuff that matters.
Re:SSH tips and tricks by MatthiasPortzel on Tuesday August 16, 2022 @07:16PM (#32490290)
"Enter" then ~ then . will kill a hung SSH connection, instead of having to close the terminal tab. I use it all the time but most people haven't heard of it.
Re:SSH tips and tricks by glandium on Tuesday August 16, 2022 @10:34PM (#32491640)
Related: "Enter" then ~ then "C" will open a command prompt that allows to add/close port forwardings. There others. Try "Enter" then ~ then "?".
Re:SSH tips and tricks by nneonneo on Wednesday August 17, 2022 @11:11AM (#32497449)
Also related: if you use ControlMaster, then the master session takes over any port forwardings defined in new shared sessions. So you can “ssh host” once to establish the master, then “ssh host -L… -R…” to make port forwardings in new shared connections; the shared sessions can be closed and the forwardings will stay active so long as the master doesn’t close.
Re:SSH tips and tricks by ptman on Thursday August 18, 2022 @03:45AM (#32506555)
Is that documented as intentional? Seems weird to me that the process shutdown wouldn't tear down the forwarding
Re:SSH tips and tricks by psanford on Tuesday August 16, 2022 @08:50PM (#32490972)
This is a great tip that I use all the time.

To be more precise ~ is the default ssh escape character. It is only treated as the ssh escape character if it is at the beginning of a new line. From the ssh(1):

> The escape character followed by a dot (`.') closes the connection; followed by control-Z suspends the connection; and followed by itself sends the escape character once.

Re:SSH tips and tricks by GekkePrutser on Wednesday August 17, 2022 @12:09AM (#32492226)
And if you're deeper in nested SSH sessions you can use a number of ~s to indicate which one to kill.

There's more commands than the dot too but I admit I forgot the others

Re:SSH tips and tricks by francislavoie on Wednesday August 17, 2022 @02:47AM (#32493092)
Ahhh that would explain why it didn't feel consistent for me, since I use ProxyCommand to hop through another box most of the time. I usually need to do that key sequence twice. But I guess now I know I just need the tilde twice.
Re:SSH tips and tricks by fragmede on Wednesday August 17, 2022 @03:27AM (#32493332)
I think the ProxyJump config option will help you.
Re:SSH tips and tricks by tominous on Wednesday August 17, 2022 @08:05AM (#32495147)
ProxyJump (or the -J option as a shortcut) plus TCP port forwarding (-L/-R) is ridiculously powerful. You can chain jump hosts with commas, threading a port forward deep into (or out of) multiple server hops with a single command.
Re:SSH tips and tricks by jrib on Tuesday August 16, 2022 @09:18PM (#32491134)
Also,

~?

will print a list of the available escape sequences.

Re:SSH tips and tricks by askvictor on Tuesday August 16, 2022 @10:35PM (#32491644)
That needs an enter first? That might explain why I've always found ~. to be so unreliable
Re:SSH tips and tricks by IcePic on Wednesday August 17, 2022 @03:20AM (#32493282)
It is so that you don't quit every time you paste "foobar~.baz" through the terminal.
Re:SSH tips and tricks by mi_lk on Wednesday August 17, 2022 @07:19AM (#32494732)
it's because the escape character is only recognized at the beginning of a line
Re:SSH tips and tricks by diftraku on Wednesday August 17, 2022 @04:47AM (#32493884)
For those of us in the dead key land (using AltGr to type ~), remember to hit space after typing out the ~, otherwise it won't register properly.
Re:SSH tips and tricks by BrandoElFollito on Wednesday August 17, 2022 @10:41AM (#32497072)
I did not need to type the space. Just AltGr ~ (nothing is output) and then .
Re:SSH tips and tricks by Infernal on Tuesday August 16, 2022 @09:00PM (#32491021)
It can also be used for nested connections. E.g. if you SSH to server A, and then from server A to server B, ~. will kill the session on B. Alternatively, ~~. will kill the session on A.

EDIT: I started distrusting my memory here and went hunting, it appears my memory has the escape nesting backwards https://lgfang.github.io/computer/2009/05/08/quit-nested-ssh...

Re:SSH tips and tricks by blueflow on Wednesday August 17, 2022 @03:13AM (#32493237)
Documented in ssh(1), section "ESCAPE CHARACTERS".
Re:SSH tips and tricks by walrus01 on Tuesday August 16, 2022 @09:00PM (#32491022)
somebody should find a way to map +++ATH0 to that same sequence for fun
Re:SSH tips and tricks by GekkePrutser on Wednesday August 17, 2022 @12:11AM (#32492242)
And then some random garbage and NO CARRIER to confirm the disconnection :)

It was [wait]+++[wait] and then ATH or ATH0 by the way, on a modem that implemented the Hayes command set correctly. To avoid at least some inadvertent triggering of this in-band signalling.

Re:SSH tips and tricks by linsomniac on Wednesday August 17, 2022 @01:15PM (#32499081)
Re:SSH tips and tricks by brianpan on Tuesday August 16, 2022 @10:33PM (#32491633)
Thank you! I will be doing a lot less "<return><return><return>...wait for connection to timeout"!
Re:SSH tips and tricks by madmax108 on Wednesday August 17, 2022 @01:39AM (#32492752)
Whoa... I was today days old when I learnt this.
Re:SSH tips and tricks by jaygreco on Wednesday August 17, 2022 @12:15AM (#32492265)
Thank you. I remember hearing about this but couldn’t remember the sequence! I tried spamming ~ but gave up when it didn’t work
Re:SSH tips and tricks by scbrg on Wednesday August 17, 2022 @01:43AM (#32492771)
You could have looked it up. It's under ESCAPE CHARACTERS in the man-page :)
Re:SSH tips and tricks by lapser on Wednesday August 17, 2022 @05:36AM (#32494126)
Woah. I recently saw this shortcut when I discovered tmate. Didn't realise it was a general ssh thing. Good to know!
Re:SSH tips and tricks by jbki on Wednesday August 17, 2022 @09:00AM (#32495735)
is this the same as hitting CTRL-D?
Re:SSH tips and tricks by throw0101a on Wednesday August 17, 2022 @09:24AM (#32496017)
>> "Enter" then ~ then . will kill a hung SSH connection

> is this the same as hitting CTRL-D?

No. ^d is a character that is sent to the remote shell (bash, zsh, etc) to tell it to exit. ~. is something for the SSH client to tell it to cut the connect if (e.g.) the shell has hung.

Thing of it like working at different OSI layers: ^d is HTTP, while ~. is like TCP or IP.

Re:SSH tips and tricks by elktea on Wednesday August 17, 2022 @06:15AM (#32494354)
amazing tip, needed this today!
Re:SSH tips and tricks by k0k0r0 on Tuesday August 16, 2022 @07:55PM (#32490630)
I sincerly hope that works.