Sharing SSH sessions using dtach
This is the first of the things I will be posting from my old website.
So, here's a way to share an SSH session with someone, using a handy little app called dtach. First off, you need to install dtach.
If you're using FreeBSD: it's in the ports tree under "misc". If you're running debian / ubuntu you can install it with
sudo apt-get install dtach
For anyone familiar with GNU Screen, dtach is very similar - but not as fully featured. Anyway...
Let's say I've got two users logged in via SSH. They're called "bill" and "ben". Seeing as they need to be sharing sessions, I've created a group called "dtgrp" and added them both to it. Ben wants to share Bill's session. So Bill fires up dtach, like so:
[bill@hitler ~]$ dtach -c /tmp/billandben bash
Great! But what now? Ben can't connect to the dtach session yet because the file permissions won't allow it. Time for Bill to detach from the dtach session using "^\" (Ctrl + \) and change the permissions.
[bill@hitler ~]$ chgrp dtgrp /tmp/billandben
[bill@hitler ~]$ chmod g=rw /tmp/billandben
He's a clever guy, that Bill! He's changed the permissions and can connect to the dtach session again with:
[bill@hitler ~]$ dtach -a /tmp/billandben
Ben can then run the same command to connect to the session too!
Flash, bang, and as if by magic: they're both sharing the same dtach session. Either of them can detach from it at any point using "^\" and the session will only end completely when someone types "exit" and hits that big funny shaped key with a bent arrow on it.
A great thing about all of this is that if Bill or Ben loose their connection, kill their SSH session by mistake or have a power cut: they can just re-connect later and re-join the dtach session.First posted: Thu, 08 Jan 2009 22:35:31 +0000