0

I would like there to always be a tmux session on a socket in /tmp/shared with a session of 0. That way I can always attach to the session via SSH:

ssh user@www.example.com -t tmux -S /tmp/shared attach-session -t 0

I want it to be shareable with other users and be able to recreate itself if a less knowledgeable, or careless user uses exit instead of [ctrl] + d when leaving the session.

I'm sure it's possible to do this in a cron, but I don't know that there isn't a better way.

1

Creating a socket file owned by selected users mutual group and using a session name would be better then using session number.

/// Create session
tmux -S /tmp/shareds new -s sharedsession
/// Change ownership to group
chgrp mutual_group_name /tmp/shareds
/// Run this in other user or ssh session to attach yourself
tmux -S /tmp/shareds attach -t sharedsession

A few ways to check session status:

  1. you can create a cron but it will delay creation of sharedsession because of minimum 1 minute rule.
  2. init.d script to run it as a service, similar to this one
  3. you can install supervisord and use it to auto daemonize your shared session creation script

Last year i used tmate running as a daemon. You can create a tmate server and attached sessions from different machines with using daemonized tmate in them. But i can not guarantee security for this cause i used them in a private network.

0

The following attaches to session 0 or creates a new session:

tmux new-session -t 0 || tmux

I don't think that you can create sessions with a specific session number, so you might want to consider using a session name. However a custom socket may well be good enough for your situation.

I'm assuming here that if session 0 doesn't exist that it will be created.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.