Profile picture
FreeBSD Frau @freebsdfrau
, 8 tweets, 2 min read Read on Twitter
I wonder how many of my followers know about ssh's builtin session management prompts? To explore this, I first need to explain why initial tilde(s) (~) seem to be "eaten" by your shell. Strap in for a fun one, you either already knew about this or this might just shock you 1/?
2/? While ssh'd to another host, after you press ENTER (this only works after pressing ENTER) press tilde (~). It won't appear on screen. Press tilde again. If you are ssh'd more than once (e.g., ssh -> ssh -> shell), it still won't appear. For each ssh, +1 tilde is eaten
3/? If you are 4 ssh's deep (e.g., from laptop: ssh A -> ssh B -> ssh C -> ssh D -> login shell on server D) you have to press tilde (~) 5 times after ENTER to get it to appear on the shell prompt of your login shell on server D. There is hidden magic in those missing tildes ...
4/? Following the 4x deep ssh example: If you press tilde (~) Ctrl-Z you land back at the laptop (and fg resumes the shell session on server D). Pressing tilde tilde (~~) Ctrl-Z you land on A. Tilde x3 (~~~) Ctrl-Z lands you on B. Tilde x4 Ctrl-Z gets you back to C. But wait ...
5/? You can dynamically enable port forwarding features from inside the ssh session. Say you forgot to add -L1234:target:22 or you don't want that displayed in ps because you want to try and hide it. Press (in order) ENTER ~ Shift-C. This gets you the "ssh>" prompt. Type ? ENTER
6/? This is ssh's builtin session management prompt. It is semi-interactive in that you can give it one command or press ENTER and you are then put back into your interactive shell session. To get back into it you have to use the sequence again (ENTER, 1 or more ~'s then Shift-C)
7/? When you are ssh'd through a system, this is a sneaky way to hide your port forwards from the likes of ps, w, and other process accounting methods. Someone using lsof (Linux) or sockstat (FreeBSD) will still see the socket tied to your ssh though 😈
8/8 One last tip. If you press ENTER, 1 or more ~'s, then ? (instead of Shift-C like we had been doing), you instead get this. The builtin session management help. Here we see ~C and others like well-known ~. and ~^Z but also others. Now you know builtin ssh session mgmt 💁🏼
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to FreeBSD Frau
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member and get exclusive features!

Premium member ($3.00/month or $30.00/year)

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!