Why do I get a "do not connect to server" message from tmux when trying to enumerate sessions?

Here's what happens to me: I start tmux sessions using tmux -L name1 , tmux -L name2 ; then I turn them off using ctrl + B + d . Then I try to get a list of current sessions on my computer. However, when I start tmux ls , I get an error message:

 failed to connect to server: Connection refused 

This is mistake? I am familiar with the screen; I think screen -ls is a very useful feature, as I can start a session and leave it working for several weeks until the next time I plug it in. Because of this, being able to list current tmux sessions is very important to me. Why tmux ls return a connection failure error when I know that tmux is running?

+45
linux terminal screen ssh tmux
Mar 12 2018-12-12T00:
source share
10 answers

Try tmux -L name1 list-session .

+3
Mar 12 '12 at 18:16
source share

This happens to me when I have no sessions. I'm just starting to use tmux and I donโ€™t understand that if you restart your computer, you will lose your sessions, which at first surprised me.

For those of you who think the same: Restore a tmux session after a reboot . Publication Summary: Use shell scripts to create tmux sessions, or create a fantastic shell history tracker .

+30
May 19 '13 at 18:19
source share

TL; DR: Try sending a SIGUSR1 signal to the tmux server process.

In my case, after about 8 days of inactivity, I was unable to reconnect:

 $ tmux attach no sessions 

However, grep for the tmux process got me this result:

 $ ps -aef | fgrep -i tmux hari 7139 1 1 2016 ? 2-20:32:31 tmux hari 25943 25113 0 22:00 pts/0 00:00:00 fgrep --color=auto -i tmux 

As pointed out by @ 7heo.tk, this indicates that the tmux server is still running, but tmux ls was failed to connect to server: Connection refused . I confirmed that the tmp directory belonging to the tmux session exists, and lsof -p 7139 (the pid of the tmux server) showed that the socket file was open:

 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME tmux 7139 hari 5u unix 0x0000000000000000 0t0 1712879255 /tmp/tmux-50440/default 

I also tried to explicitly point -S /tmp/tmux-50440/default to tmux, but that didn't help. However, I read on the tmux man page that sending SIGUSR1 will force tmux to recreate the socket file, so I tried this and I was able to immediately find the session and reconnect:

 $ kill -s USR1 7139 $ tmux ls 0: 12 windows (created Mon Apr 18 21:17:55 2016) [198x62] 
+28
Jan 02 '17 at 6:16
source share

This happened to me when the Ubuntu desktop crashed and my dwarf-terminal windows came out. I could still see that the tmux process was running ( ps aux | grep tmux ), but for some reason the tmux commands would not work to list existing sessions. Apparently, he did not detect an existing Unix socket while tmux was running. The fix in this scenario is to find an existing Unix socket and specify it in tmux using the -S flag; here as:

You can find the PID of your still running tmux process as follows:

 ps -p $(pidof tmux) 

Now take your PID (in my case, 6876) and run it to display all open Unix sockets:

 sudo lsof -Uap 6876 

Hope you see the output as follows:

 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME tmux 6876 abe 3u unix 0x0000000000000000 0t0 408477 socket tmux 6876 abe 4u unix 0x0000000000000000 0t0 408478 socket tmux 6876 abe 6u unix 0x0000000000000000 0t0 408479 /tmp/tmux-1000/default 

Now you can indicate that the existing Unix socket is for your tmux command (using the -S flag), and you should be able to list the sessions and properly attach:

 tmux -S /tmp/tmux-1000/default list-sessions tmux -S /tmp/tmux-1000/default attach -t 0 
+12
Jan 11 '16 at 4:52
source share

You really get this error if the session is not open. If there are no sessions, there is no tmux server, so it cannot connect to it.

With the -L option, you change the name of the socket that the tmux server uses, this is not a way to name your sessions. You are better off using the following commands:

 tmux new -s name1 tmux new -s name2 

They will create 2 sessions on the server with the default socket name. Now you can do:

 $ tmux ls name1: 1 windows (created Mon Sep 22 10:34:40 2014) [158x40] (attached) name2: 1 windows (created Mon Sep 22 10:34:43 2014) [158x40] (attached) 

And you will see all sessions running on the server in the default socket. You can connect one of them using:

 tmux attach -d -s name1 

-s indicates the name of the session
-d will disconnect it from the previous client (if it is connected)

You can also switch between sessions inside tmux using the choose-tree command, which is assigned by default by pressing the Cs key (key + s prefix). This is what I usually do.

+11
Sep 22 '14 at 8:43
source share

You may have an error in .tmux.conf . I had this problem until I pulled this line from my .tmux.conf :

 set-window-option -g xterm-keys on 

You can also try tmux -v and then see the logs it prints.

+8
Mar 17 '13 at 16:40
source share

I used another program inside tmux (reattach-to-user-namespace), and I got this error when switching computers, because the space for reconnecting to the user was not set. The brew install reattach-to-user-namespace was simply to run brew install reattach-to-user-namespace .

+3
Jun 11
source share

One simple fix is โ€‹โ€‹to delete the tmp files left by the tmux server, for example by executing $ rm -rf /tmp/tmux-xxx/ .

+3
Jan 12 '15 at 20:38
source share

The TMUX(1) method is that the client process ( tmux ) connects to the server process ( tmux also, but not tied to TTY), as shown below: ps output:

  PID TTY STAT TIME COMMAND 19229 pts/1 S+ 0:00 tmux 19231 ? Ss 0:00 tmux 

This shows that the client actually starts in front of the server (we can assume that it deploys it).




After disconnecting / reconnecting, the ps command outputs:

  PID TTY STAT TIME COMMAND 19231 ? Ss 0:00 tmux 19290 pts/1 S+ 0:00 tmux attach 

This shows the tmux client as tmux attach , so it is a little easier to understand.




Now, if we look at the output of pstree in both cases, we get in both cases (ignoring the pid change for tmux attach ):

 pstree -p init(1)โ”€โ”ฌโ”€acpid(1824) โ”œโ”€cron(1859) โ‹ฎ โ”œโ”€sh(14146)โ”€โ”€โ”€tmux(19229) โ””โ”€tmux(19231)โ”€โ”€โ”€sh(19233)โ”€โ”€โ”€pstree(19234) 

It is clear that the commands typed ( pstree in this case) in the client process (PID 19229 ) are executed by one server (PID 19231 ), which allows them to continue without SIGHUP if the client terminal is lost (for example, via ssh).




Now, to the question, O.P. asked: what happens when tmux returns failed to connect to server: Connection refused , is that the server process (pid 19231 in our case) is unavailable, regardless of the reason (maybe because that the server process is dead, and also because the user running the tmux client does not have access rights to the tmux socket, etc.)

The solution in this case is grep for tmux processes (for example, via ps ) and I pray that you do not get this error because the server is dead (so you can attach to it using lsof to find out which sockets it is listening to). Otherwise, it is impossible to connect to the server, because it is dead, as after a reboot.




TL; DR:

This error can be set for several reasons: from an error to a critical failure (the program died). In short, use the UNIX tools at your disposal to determine which socket tmux uses if it is still working (there must be at least two processes if your tmux client is running - this happens after calling tmux or tmux attach from the shell), and thus, if you have lost the session or not.

Note. As pointed out in other answers, if the cause of this error is a socket error, you can use the -L flag to tell tmux use a specific socket.

+3
May 13 '15 at 9:52
source share

This can happen if you or any cleaning process delete the files in /tmp/* . All your session data is lost if you cannot recover these files. Killing all instances of tmux and restarting is the only option, unfortunately.

+1
Feb 10 '16 at 15:18
source share



All Articles