How can I open multiple terminals tabs from one remote SSH such that they are visible as overlay tab in one terminal tab?
Similar questions have been asked by other users here (0 answers) and here. Both of then suggest to use screen. But I am looking for something different. I am looking for something to install on my remote machine which lets me emulate multiple tabs (including UI) within one bash shell as if I have multiple tabs open.
One alternative is to change bashrc of the machine I am working on such that it automatically logs into the remote whenever I open a new tab this side. However, this is good only when I access only one remote machine.
Solution 1:
Use tmux
.
Tmux is an alternative to GNU screen, so this answer is almost like "use screen
". However tmux windows appear in the default status line almost like tabs. With mouse support enabled you can just click to change to another window; or use your mouse wheel when the cursor hovers over the status line.
The screenshot is from PuTTY because I'm on Windows at the moment. In Linux my experience is even better:
- I run my terminal emulator that provides tabs.
- I keep the first tab local.
- In additional tabs I
ssh
to various servers. This way I have one tab per machine. - On each machine I run
tmux
. Tmux windows act like an additional layer of tabs within respective terminal emulator tabs. - In addition tmux provides panes (there are two panes in the above screenshot, both running interactive
bash
). If you're used to just one shell per tab and you want to keep it this way then just don't split tmux windows into multiple panes. For me panes are even more useful than windows in tmux.
As a side effect I have the ability to disconnect from the SSH server without interrupting anything; and to connect from the same or another computer, resume my work as if nothing happened (ssh
again, then tmux a
). I call it "side effect" in the context of your question but this functionality is often the main reason people use tmux
/screen
.
Practical hints, so you can test my solution right after you install and run tmux
on your remote machine:
-
Place this in your
~/.tmux.conf
to enable mouse support:set -g mouse on
To be clear: the file should exist on the remote side where
tmux
is about to run. Localtmux.conf
is relevant only to a locally invokedtmux
. -
tmux
runs in a client-server architecture (note: normally clients run on the same machine as the server they talk to, this has nothing to do with network). The mentioned file is read when the server starts. If you need to enable mouse support for the already running server, invoke this from a shell:tmux set -g mouse on
-
To create a new window in tmux, press this sequence: prefixc.
prefix is Ctrl+b by default, so the whole sequence isCtrl+b (release both) c.
-
To destroy a window exit all its panes. If you have just one shell in the window, just exit the shell; very much like with an actual tab.
(There is an option that makes panes survive after respective processes exit, so the window survives as well; but this is not the default behavior.)
-
To go to the next window without a mouse, press prefixn.
Interactive selection: prefixs→↓↓↑…Enter. There are other useful keystrokes.
-
Maybe you prefer tabs (their bar) at the top. If so, you will probably like tmux to display the status bar at the top as well. Place this in
~/.tmux.conf
:set -g status-position top
-
You can customize the status line so it looks more like a bar with tabs. Example:
# persistent option in tmux.conf set-window-option -g window-status-current-format '\#I:#W#F/'
# or ad-hoc in a shell tmux set-window-option -g window-status-current-format '\#I:#W#F/'