Confession time: I don’t fully understand how terminals, shells and SSH really work (and my guess is you don’t either). And I don’t mean the cryptography behind SSH. I mean how SSH and the terminal — and the shell for that matter — interact with one another.
I recently realized that even though I’ve been daily remotely logging into Linux systems for all of my adult life (and type in the shell and Vim) I didn’t really grasp how these things actually work.
I mean, it’s one of those things I kind of understand, but not completely. The author of the short linked post found four articles that detail all this stuff quite well, so go on over there and see just how well you really understood it.
I’ve worked with low level TTY APIs in the past and I strongly dislike the TTY foundations. It’s polluted with archaic things like line printers and telnet control sequences that IMHO belong in the shell rather than the kernel. Instead on unix many of these get implemented in the kernel and you use the obscure terminal API to program it. If you get it wrong it can mess with your IO. Also the way job control is managed by the kernel is very awkward to integrate with shells. I’d love to dump this complexity in favor of something much simpler but we can’t drop it now because so many things depend on leaving it as is for compatibility.
Just look at some of these things…
Luckily I don’t have to program at this level very often, but if ever you do, you’ll get thrown into a world of legacy hacks.