[Howto] Exit bad/broken/locked ssh sessions

I just have to share this: have you ever been in a situation where the SSH connection locked up, and you were not able to send any more commands? And particularly, you were not able to send commands like Ctrl+c or similar to close the session?

In such situations I usually had to close the terminal - which is not always fortunate.

But: you can just close the SSH session with an escape sequence: next time, just do Enter+~+. !So just press the enter key, followed by the tilde key followed by the dot - and you should be back to your terminal!

I use SSH on a daily base for more than ten years, but never knew about that! :sweat_smile:

Read more in the actual SSH documentation.


Also try Enter ~ ? to see the list of supported escape sequences. Your list from OpenBSD is incomplete.


Good point - I had not intention of listing all sequences, but the quote made it not clear enough that this was just an excerpt. I corrected that.

Closer to 20 years, here, and same!

And from the telnet(1) man page, I now know that telnet also has such a mode, optionally replacing its normal ^] escape sequences, which can be activated by passing it the -r switch. The switch is a nod to the mode’s origins with the rlogin command, from which ssh also apparently derives its escape sequences. #WhoKnew?

…Of course, now that I do know, I can’t really say that I’ll ever have call to use the ssh escapes. But, hey, at least now I know they’re there. Until I forget them a week from now. :roll_eyes:

8 posts were split to a new topic: Copy-pasting in tmux

Sorry—I removed the link to the blog post. In general, it is discouraged to share personal blog posts on topics, even if the intention is not self-promotion. Linking to docs is the way to go.

I didn’t knew, so it’s ok. I’m just surprised. Other parts of the Fedora universe very much welcome blogs - planetfedora is there for a reason. After reading “Discourse is not only a question and answer platform” in the “Please read me first!” I was under the impression that ask.fedora is not just “question, anser” - for that exact reason I shared my experience instead of asking a question…

Can you point me to rules or guidelines?

Planetfedora is literally a blog aggregator. :slightly_smiling_face:
However, if you do add your blog to planet-fedora it must follow the Code of Conduct, and will be removed very swiftly if it doesn’t.

No, you misunderstand me—sharing your experience is perfectly OK. That is encouraged.

The specific bit where you linked to your personal blog is what we frown down upon. If allowed, it very quickly turns into lots of spam posts, and then the admins have to go through each link to see whether it is relevant or not----which we really cannot actively keep doing. (Also note that many blogs make money from people viewing them, and so using community forums to increase viewership is frowned upon—but again, who decides what personal blog is OK, and how?)

In general, any forum you use will request you to write the solution on the forum itself instead of documenting it in a personal blog and linking to it. It’s an unsaid rule, but sure we can make it a proper written down rule if you think that’ll be better?

As an uninvolved third party, my take is: Explicit rules are always better than unwritten rules.

1 Like

(That being said, I’m afraid I have to agree: Posting useful information, great. Posting a teaser with “Here’s a link to my blog post” seems like self-promotion, even if it wasn’t intended that way.)

Yes, but on the flip side going down the path where everything is a written rule instead of a guideline that is understood by community members defeats the purpose of the idea. Rules are blindly followed, while such unsaid guidelines are passed on from community member to community member generally with an understanding of why it is so.

Let’s leave it as an unsaid guideline for now. If we see it becoming common practice for users to post links to their blogs, we’ll make it a rule to make it enforceable?


Please refer to this topic for the discussion on using tmux, and the copy pasting issues there:

Yes. And as such it is part of the community, with a lot of participants.

Which is, incidentally, written down.
But the “if you add your blog” was a good one :wink:

Anyway, thanks for taking the time to answer. I personally prefer to have things written down but that might be just me. I learned the lesson now anyway.

1 Like

I start lines with a tilde often enough to be annoyed by the need of having to hit it twice, so I changed my config to use the backtic ` instead of ~.

# ~/.ssh/config
EscapeChar `

And I’ve been in situations where I ran ssh host1, started tmux, and issued ssh host2 in one of the panes. In those situations, it’s handy to have a separate escape key for the second ssh command, otherwise it’s likely you’ll prematurely disconnect the first session (with the tmux session).

You know you don’t actually have to hit it twice, right? The ~ won’t show up immediately, but if you follow it with anything other than one of the supported escape characters both the ~ and the character that followed it will be delivered to the remote end. (So, you can follow it with anything other than . B C R V v # ^ & ?… or Ctrl+z, but that seems like even less of a worry) .

(Which I guess explains how I went so long without realizing the ~ escapes were even there. If I type ~ at the start of a line it’s usually the beginning of something like ~/path/to/executable ..., and they were smart enough not to make / one of the escapes.)

1 Like

I do know about the “fall-through” behaviour and that’s part of what bugs me about it. It’s worse in vim where ~ changes the case of the letter under the cursor. I use it quite often, and don’t like the fact that I sometimes have to hit it twice, sometimes only once.

All in all, small annoyances, but enough for me to remap the Escape character (and, as mentioned previously, with nested SSH sessions it’s handy to have different escape characters for the different levels of nesting).

(Being a pre-SSH-era veteran, I should probably change the escape character to Ctrl + ], but I still use telnet from my ssh session often enough to not go there.)

1 Like

I hear ya. One of the first things I do on a new remote system is copy in my .screenrc, because whoever thought Ctrl+a sounded like a good default escape should be shot!

(I use Ctrl+\, because I can’t imagine any situation in my life when I would ever accidentally hit that, and if nothing else it looks cool in .screenrc:

escape ^\\\ #sooo_slanty!

Plus, since screen’s default binding for “other window” is also ^\, it means I can quickswap between my two most recent screen virtual-terminals by holding down Ctrl and double-tapping \\.)

1 Like

Well, Ctrl + \ traditionally sends the SIGQUIT signal which sometimes comes in handy. I figured that Ctrl + Space (aka ^@) would be pretty rare: it sends a NULL character. I haven’t really needed that, so I figured it would make an excellent command prefix for screen/tmux. :sunglasses:

1 Like

Woah, easy there! Let’s not get murderous over a default escape sequence :laughing::laughing:


You’re right! Killin’ lets 'em off to easy.

Whoever made that choice should be made to suffer. S l o w l y !