Friday, December 20, 2013

Concurrently sharing a Linux terminal across different ssh sessions or terminal emulators

How can I share a terminal session in two different terminal emulator windows or ssh sessions?

Why?
I run pianobar on an old laptop to listen to music from Pandora. I usually start pianobar through ssh from another laptop to be able to control it from the other room. However when I am moving between rooms, I have to terminate pianobar across the ssh session and start it locally on the old laptop if I want to control it.

How?
I have been using the "screen" command for some time to maintain sessions across different ssh sessions. It turns out "screen" has a multi-user mode.

To share a terminal, you just follow these steps:
  1. Start "screen" through an ssh session or a local terminal emulator.
  2. Go to the another terminal session and start "screen -x". You will need to specify the tty to attach to if you have started more than one. 
  3. Voila ! These two sessions are identical. You can follow the progress of a command or control it simultaneously from both sessions.
Final note: This requires "screen" to be compiled with multi-user mode support which I have found to be the case for Mac OS X 10.9 and Debian 5. I assume it's enabled by default but just in case.

Back to listening to pianobar now :)

No comments:

Post a Comment