I engage in quite a bit of troubleshooting and IT support for friends and family. A tool that has always made it easier for me to do this is tmate for terminal sharing. It is something akin to screen sharing, but on the terminal.
The major benefit with tmate is that I can bootstrap a quick entry into their system with ease and no effort on their part, while those interested could follow and troubleshoot their PCs along with me. Working with tmate is easy. Install on your favourite distro, then run:
tmate
The user should see a tmux session start with a handy dandy ssh command that looks something like this:
Tip: if you wish to use tmate only for remote access, run: tmate -F
To see the following messages again, run in a tmate session: tmate show-messages
Press <q> or <ctrl-c> to continue
---------------------------------------------------------------------
Connecting to ssh.tmate.io...
Note: clear your terminal before sharing readonly access
ssh session read only: ssh [email protected]
ssh session: ssh [email protected]
tmate
outputssh [email protected]
ssh [email protected]
This would be the end of the tutorial and for all intents and purposes it is. Share this session with the other person and you are done, you have a two-way terminal sharing session.
But if like me and have always been greedy, then continue reading.
Self-Hosting a tmate-ssh-server instance
I decided to host my very own tmate-ssh-server. Why would one need to do so? I find for one, self-hosting fun and exciting while at the same time being reliable. The official default servers don't always run and are in some way or other rate-limited. So began my quest to run my own instance of tmate's ssh server.
If you'd be content with having a look at my docker-compose and calling it a day, then here's a link to it:
There's not much to it but three simple steps.
# Clone this repository and cd into tmate
git clone https://github.com/aakashhemadri/dockerfiles.git
cd dockerfiles/tmate
The next step is to key in what's special about your setup. You may enter the domain/IP to your server, whether it's behind a reverse proxy, ports, or more.
# Make a copy of .env.example into .env and edit the appropriate variables
cp .env.example .env
nano .env
To explore and learn more about the environment variables in use, visit the docker hub page.
Create keys and start tmate-ssh-server:
# Run this to setup and start tmate-ssh-server
./setup.sh
Here, we use tmate's own script to create ssh-keys and mount them as a volume inside the docker image. My script lets you have a look at its contents before you run it. So, make sure everything is perfect and nothing is amiss.
As the script has run its course, it'll print the configuration necessary to use your tmate-ssh-server on a client. Save that in ~/.tmate.conf
file and share it with whomsoever would like to use your instance. docker-compose should have initialised tmate-ssh-server as a background service on a successful run of the script. Once everything looks good after having a look at the logs docker-compose logs -f
. Like earlier, run:
tmate
tmate
with configuration set in ~/.tmate,confYou now can share your new tmate instance hosted on your very own server!