Support Support Downloads Knowledge Base Apex Support Portal Community

Knowledge Base

Search our Knowledge Base sites to find answers to your questions.

Ask All Knowledge Base Sites All Knowledge Base Sites JunosE Defect (KA)Knowledge BaseSecurity AdvisoriesTechnical BulletinsTechnotes Sign in to display secure content and recently viewed articles

[Contrail] How to detach and reattach a tmux session in Contrail



Article ID: KB37201 KB Last Updated: 14 Jul 2021Version: 1.0

In KB37200 - [Contrail] How to split and select a pane using tmux in Contrail, a demonstration was made on how to initiate a tmux session and log in to multiple target Contrail nodes in an RHOST13 Contrail environment.

This article demonstrates one of the most useful features of tmux: detaching and reattaching a session.


One of the well-known benefits of running remote sessions in tmux is that even when the login session to the remote server gets lost, all sessions started on the remote server inside of tmux will persist. For example, consider that there are some temporary Internet issues, and the first SSH session toward the RHOST13 host is disconnected. Naturally, the second SSH session from the RHOST13 host to the undercloud server will be disconnected too. However, the third SSH session that was initiated from the undercloud server to the target Contrail node will remain up and connected because it was started from inside of a tmux session.

That is, tmux sessions will persist regardless of the connectivity between the local PC and the remote server. When you reconnect, you need to rebuild only the first and the second SSH sessions, and then you can "reattach" the target SSH session with tmux. This article demonstrates how to reattach the target session with tmux by using an example.

Initially, you will have a 4-pane tmux window running in your tmux session:


Suppose that you experience some network issues at this time. The first SSH session to the RHOST13 host then gets disconnected.


When the network becomes stable, you can log back in to the RHOST13 host and the undercloud manually as shown.

$ ssh
Last login: Sun Jun 13 19:37:45 2021 from
[root@global-intel4 ~]# ssh stack@undercloud
Last login: Sun Jun 13 22:37:37 2021 from

Now you are back to where you were immediately before you initiated your tmux session. You can now list all current tmux sessions as shown.

[stack@queensa ~]$ tmux ls
jtac: 1 windows (created Sun Jun 13 12:52:57 2021) [274x70] (attached)
ps: 1 windows (created Sun Jun 14 18:22:32 2021) [274x70] (attached)

In this example, you see two tmux sessions: "jtac" is the one initiated in KB37200 - [Contrail] How to split and select a pane using tmux in Contrail; "ps" was initiated by someone else. Here you want to continue only with your sessions, so you do as indicated below:

[stack@queensa ~]$ tmux attach -t jtac

Immediately all the panes and SSH sessions to the target node inside each pane come back. Suppose that there is no network issue between the undercloud server and the Contrail nodes. In this case, the pane layout and look should be exactly the same as what they were before you got disconnected.

This saves the need to list all nodes again, split windows into panes, and reconnect each node in the panes. The session retains whatever you had earlier, including a cache of historical command output in each session. This feature is very useful for daily maintenance and operation tasks.

Further, the tmux session can also be manually detached. This is used when you need to exit from the Contrail environment, while leaving your sessions from the undercloud server to the Contrail nodes connected for later usage. The session detaching can be done by pressing "ctrl-b + d".

[stack@queensa ~]$ tmux attach -t jtac
[detached]  #<---
[stack@queensa ~]$

Now you are back to where you were before the tmux session was started. You can logoff as usual from here when your work is done, leaving all your Contrail node login sessions intact.

Comment on this article > Affected Products Browse the Knowledge Base for more articles related to these product categories. Select a category to begin.

Getting Up and Running with Junos

Getting Up and Running with Junos Security Alerts and Vulnerabilities Product Alerts and Software Release Notices Problem Report (PR) Search Tool EOL Notices and Bulletins JTAC User Guide Customer Care User Guide Pathfinder SRX High Availability Configurator SRX VPN Configurator Training Courses and Videos End User Licence Agreement Global Search