DebugPointer
Published on

How to disconnect all other tmux users

How to disconnect all other tmux users

Tmux is one of the most useful tool when it comes to using using a linux terminal.

Tmux is a terminal multiplexer, it allows a user to access multiple terminals (or windows), each running a separate program, while providing a single screen to work on. Tmux is useful for running more than one command-line program at the same time, increasing productivity and the way you work.

Tmux is one of the "terminal multiplexer", it enables a number of terminals (or windows) to be accessed and controlled from a single terminal. It allows you to create a session on a remote box, run applications in that remote session, "detach" from the session, and re-"attach" when desired. It also has advanced features such as multiple windows and split views. Using tmux is recommend when running an interactive CLI program remotely. If you get disconnected from your session, you can re-attach as though nothing happened.

One of the most frustrating thing is when many users attach to your tmux session and you have lost complete control of the situation. Worry not, there is a way to disconnect all other tmux users from the session, when you can be your tmux session's ruler.

You can use <prefix> D to choose choose the client you want to detach. This will also list the clients and when was the last time they used it.

Please note- Use CAPITAL LETTER 'D' (shift + d)

Here, let's assume that your <prefix> is Ctrl-B, which is the default prefix.

Ctrl-B + D

Details of the option-

detach-client [-P] [-a] [-s target-session] [-t target-client]
               (alias: detach)
         Detach the current client if bound to a key, the client specified
         with -t, or all clients currently attached to the session speci-
         fied by -s.  The -a option kills all but the client given with
         -t.  If -P is given, send SIGHUP to the parent process of the
         client, typically causing it to exit.

In a tmux session, tmux detach-client -a will detach all other clients except the current one.

You can also create a function in your ~/.bashrc -

detach_others () { tmux detach-client -a;}

So you can simply call detach_others from your terminal, and all other sessions will be detached.