Picture a scenario where I'm logged into a server (which we'll call "Wallace") from my local machine, and from there I ssh
into another server (which we'll call "Gromit"):
laptop ---ssh---> Wallace ---ssh---> Gromit
Then the ssh session from Wallace to Gromit hangs, and I want to kill it. If I enter ~.
to kill ssh, it kills the ssh session from my laptop to Wallace, because the ~
is intercepted by that ssh session, and the .
is taken as a command to kill the session. How do I send a command to the ssh session between Wallace and Gromit? How do I kill my "inner" ssh?
Add another tilde (ie, type
~~.
). Each successive tilde is eaten by the outermost ssh session which hasn't yet eaten one, but if the next character is another tilde, it's passed along to the next session in.If, from gromit1, you ssh'ed to a third host (let's call it wensleydale), then
~~~.
would drop the session to wensleydale and return you to a prompt on gromit.1 And what a great server that is; how often have I heard a developer remark "cracking host, gromit"?
You can issue arbitrary commands, and catch the output from the innermost shell into a variable