I'm pretty new with Tmux. I'm looking for a way to connect a Tmux session locally to a distant one, running on my server with irssi and other stuff.

If i start a regular session with


And then connect to my serv with SSH, Tmux lost the conneciton every time i close my laptop.

In the other hand i tried to connect to my serv, starting a tmux session there, then attach o local one with

ssh myserv.com -t tmux a

But, after a AFK break i was not able to reconnect...

I'm pretty sure there is a way to do it, any clue ?


as jmreicha said.

start tmux on the remote server, but instead of connecting to that server with ssh...

use mosh.

you will never lose connection again, even if you let the computer sleep for weeks at a time, or change from home wifi to mobile and then onto free public wifi.

who needs scripts eh :)

  • I'm surprised at the downvote you got. Maybe someone disliked your tone? mosh is awesome anyway. – Erik Garrison Oct 8 '15 at 12:07

You want to start your tmux session on the remote host, and just keep it running in the background. For example, run the tmux command on the remote server to start it up. Then from your local machine SSH to the server and run tmux attach -t 0 to attach to the tmux session 0.

Then when you are done, just detach the session, with a CTRL-A CTRL-D and leave it there until you need to connect again.

Make sense?

  • Yeah, it works. But there is no way to do it without reconnect manually ? – x_vi_r Apr 9 '13 at 7:06
  • Hmm, I guess I'm not quite sure I understand what you're asking then. Maybe update your question with some more detail about your scenario. I'm guessing you will want some sort of script to do this but I need to know what you are wanting to have happen first. – jmreicha Apr 9 '13 at 13:44

I think you need to move the '-t' part at the beginning, like this:

ssh -t myserv.com tmux attach

(inspired by: this)


This might make things easier. For one, it might help to have a tmux configuration file with lines like:

new-session -s mysession "bash -i"                     #window 0, run bash
new-window -n IRC "irssi -n x_vi_r -c DALnet; bash -i" #irssi in window 1
new-window -n Diag "tail -f /var/log/maillog"          # window 2, run maillog tail
split-window -h "top"                      # split 2nd window in half, run top
select-window -t 1 # select Window 1 (which has IRC in it)
attach-session -t mysession

Then you should be able to do ssh -t user@server.com "tmux attach -d" and your stuff will start if it isn't already running.

My irssi is set to connect to Dalnet in this example. If I chose to /quit IRC, a bash terminal starts in that window. If you don't like that, delete the bash -i and preceding semicolon. The third window is just an example of a split pane for "other stuff."

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.