5

I have a tmux session already running. I have created it just with

tmux

now I can leave the session and re-enter with

tmux a -t 0

how can I share this session with other users? Usually one has to create the session with -S option, but I haven't. Is there a way to share my session?

wiso
  • 161
  • 1
    http://unix.stackexchange.com/questions/2523/what-are-other-ways-to-share-a-tmux-session-between-two-users – Ramesh Aug 26 '14 at 16:02

1 Answers1

5

You can use tmux grouped session.

First, create initial session, change its name to share:

$ tmux
$ tmux list-session
0: 1 windows (created Wed Aug 27 00:14:05 2014) [80x23] (attached)   
$ tmux rename-session -t 0 share 
$ tmux list-session
share: 1 windows (created Wed Aug 27 00:14:05 2014) [80x23] (attached)

Then, from other client, you simply add -t option and grouped session name (in this example, it's share) to tmux new-session command:

$ tmux new-session -t share -s cuonglm

-s option set the session name. If other user, i.e wiso, want to attach grouped session, he simply do:

$ tmux new-session -t share -s wiso

From man tmux:

If -t is given, the new session is grouped with target-session. This means they share the same set of windows - all windows from target-session are linked to the new session and any subsequent new windows or windows being closed are applied to both sessions. The current and previous window and any session options remain independent and either session may be killed without affecting the other. Giving -n or shell-command are invalid if -t is used.

cuonglm
  • 153,898
  • session not found: share. How the new user should find the session of the first user? – wiso Aug 26 '14 at 17:32
  • @wiso: You must make an initial session, by typing tmux. Default session name 0. Other user can type tmux list-session to list all sessions. – cuonglm Aug 26 '14 at 17:34
  • the other user don't see the sessions of the first user. tmux; su; tmux list-sessions -> failed to connect to server – wiso Aug 27 '14 at 09:44
  • @wiso: failed to connect to server meaning you have not started tmux yet. – cuonglm Aug 27 '14 at 09:46
  • the main user started a tmux session. Now root want to join the session of the main user. – wiso Aug 27 '14 at 09:49
  • @wiso: It does not matter root or any user. Do you follow my example and it works? – cuonglm Aug 27 '14 at 10:22
  • tmux; (control B + d to exit from tmux); tmux rename-session -t 3 share2; su; (enter root password) tmux new-session -t share2 -s wiso -> session not found: share2 – wiso Aug 27 '14 at 15:31
  • @wiso: What is 3? tmux default sesssion is 0. And it seems that you have quited tmux, so the session does not exist anymore. After type tmux, type tmux list-session to get the session name(default to 0). Then join tmux session group in other terminal. – cuonglm Aug 27 '14 at 15:58
  • 1
    3 because I have other 2 sessions. No, I haven't quitted tmux, as I have said I've done control+b d, which [detach] the session, doesn't close it. – wiso Aug 28 '14 at 10:39
  • @wiso: So I think it must be 2 because default tmux session name start at 0. You should try tmux list-session to obtain the right name. – cuonglm Aug 28 '14 at 10:42
  • 1
    sorry, I have 3 sessions. It's not this the point. 3 is correct, I have checked with tmux ls. The point is that the second (linux) user do not see the sessions of the first user. – wiso Aug 28 '14 at 17:17