TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

How to kill an unresponsive SSH session

209 pointsby oarmstrongalmost 12 years ago

19 comments

jerfalmost 12 years ago
Read the SSH man pages every so often, even if you think you know how to use it. There's a lot of features in there. Don't miss the "AUTHORIZED_KEYS FILE FORMAT" in sshd's man page for the uber-cool "command='command'" options for authorized keys (restricts a given key to just be able to run a certain command, very useful). See also SSH's port forwarding, -D, learn how to use ssh-agent, and "man ssh_config".
评论 #6108711 未加载
spindritfalmost 12 years ago
Or use mosh[1] on top of SSH and stop worrying about that stuff.<p>It works much better over high-latency links (mobile). It is not bothered by saturated links, tolerates IP changes and losing the underlying connection like when you suspend your laptop and take it elsewhere.<p>I now have mosh connect to several servers in tabs when I run gnome-terminal the first time, and only disconnect on reboot. I also run a mosh-capable Irssi Connectbot fork on the phone[2].<p>It&#x27;s a massive improvement, fixing many of the little annoyances of ssh.<p>[1] <a href="http://mosh.mit.edu/" rel="nofollow">http:&#x2F;&#x2F;mosh.mit.edu&#x2F;</a><p>[2] <a href="http://dan.drown.org/android/mosh/" rel="nofollow">http:&#x2F;&#x2F;dan.drown.org&#x2F;android&#x2F;mosh&#x2F;</a>
评论 #6109254 未加载
评论 #6111048 未加载
评论 #6107970 未加载
评论 #6108101 未加载
Sharlinalmost 12 years ago
The default escape character ~ does not work if the tilde key in your keyboard layout is a dead key [1], like it is in many European layouts. It can be changed via the EscapeChar config option or the -e command line parameter. It seems, though, that not just any old character is accepted - I tried to use §, which, in the Finnish layout, is in the same physical position as ~ is in the US version, but ssh complains about &quot;bad escape character&quot;.<p>EDIT - I suppose it must be an ASCII character, which is not an entirely unreasonable requirement.<p>[1] <a href="http://en.wikipedia.org/wiki/Dead_key" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Dead_key</a>
评论 #6107892 未加载
评论 #6107891 未加载
评论 #6107873 未加载
评论 #6108411 未加载
Nursiealmost 12 years ago
enter-tilde-dot<p>It is useful, yes. Here&#x27;s another thing I picked up last week - how do you reboot a remote linux box that&#x27;s somehow lost its root drive but you still have a shell open (because you left ssh running on another machine)?<p><pre><code> echo 1 &gt; &#x2F;proc&#x2F;sys&#x2F;kernel&#x2F;sysrq echo b &gt; &#x2F;proc&#x2F;sysrq-trigger</code></pre>
评论 #6108221 未加载
adaml_623almost 12 years ago
Another useful trick to remember if you&#x27;re using Putty and you ever accidentally hit Ctrl-S and find that you&#x27;ve frozen the terminal.<p>Just type Ctrl-Q and you will unfreeze the connection.<p>Credit due to: <a href="http://raamdev.com/2007/recovering-from-ctrls-in-putty/" rel="nofollow">http:&#x2F;&#x2F;raamdev.com&#x2F;2007&#x2F;recovering-from-ctrls-in-putty&#x2F;</a>
评论 #6107917 未加载
评论 #6107807 未加载
评论 #6108530 未加载
verbatimalmost 12 years ago
&lt;enter&gt;~Ctrl-Z will suspend the ssh session, too.<p>I&#x27;ve also found it useful to do &lt;enter&gt;~C - then you can configure port forwarding without having to open a new ssh session.<p>(~C opens a command line, enter &quot;help&quot; for available commands.)
epoalmost 12 years ago
Please don&#x27;t let HN become a substitute for RTFM. This should be known by all SSH users who have skimmed the man page. Fair enough as a blog post but for this trivia to get 46 points so far is deeply depressing.<p>Maybe I should write a blog post about the use of CTRL-Z in the shell and post that here, should get me Kilo-karma points if this is anything to go by.
评论 #6108161 未加载
评论 #6108157 未加载
评论 #6108153 未加载
评论 #6108174 未加载
hahainternetalmost 12 years ago
If you happen to be a few sessions deep, ~~ will send ~ to the next session along. A casual ~~~~~~~~~~~. or so later and everything is wonderful again!
评论 #6107824 未加载
评论 #6109055 未加载
评论 #6107763 未加载
oarmstrongalmost 12 years ago
In case anyone is having difficulty with the font used on the page, the escape sequence is: newline followed by tilde (~) and then period (.).
tankenmatealmost 12 years ago
The thing that amazes me about this is that people don&#x27;t realise that this comes from BSD 4.2 rsh released in 1983.
评论 #6108697 未加载
jlkinselalmost 12 years ago
I&#x27;m a little surprised this is on HN? To me this is the equivalent of a blog post about using %d with printf.<p>Not complaining, just a little surprised something so novice would get attention...
评论 #6111112 未加载
kdazzlealmost 12 years ago
Another great solution is to just use the ServerAliveInterval option.
评论 #6108494 未加载
kbensonalmost 12 years ago
While I&#x27;ve frequently used this to kill connections, my favorite thing I&#x27;ve done with it is to list existing and dynamically add new forwarding ports through SSH.
spudlyoalmost 12 years ago
Hitting &#x27;.&#x27; at a prompt used to be a common idiom for exiting a program. I first saw it when I was a kid working on an HP-3000 system where the system programming language was BASIC and all programs followed this convention. Don&#x27;t know where it came from originally, but you can still see it in places like rsh&#x2F;SSH etc.
评论 #6109432 未加载
gbogalmost 12 years ago
Does it work too with ctrl-\ ? This has been my process killer recently and it&#x27;s powerful (and the only way I know to get out of xtail.)
Nick_Calmost 12 years ago
On a side note, does anyone know what ~B actually does? Does it send a SIGINT to the remote terminal? What does ssh mean by the phrase &quot;send a BREAK to a remote system&quot;?<p>I&#x27;ve tried to use it without success to kill a runaway listing of megabytes of scrolling text, but frantically hitting ctrl-C seems to work much better.
评论 #6111801 未加载
bostonvaulter2almost 12 years ago
This usually doesn&#x27;t work for me. Perhaps it&#x27;s because my sessions are usually multiplexed via &quot;ControlMaster auto&quot;?
anurajalmost 12 years ago
[Enter] Shift+~ .
microcolonelalmost 12 years ago
I&#x27;m surprised&#x2F;apalled at how many people upvote this, considering how this place is supposed to be &quot;hacker news&quot;...
评论 #6109720 未加载
评论 #6109185 未加载