xpanes, a parallel ssh tool

xpanes, a parallel ssh tool

iIdeally, you don't need to log into your Linux servers. They are set up and managed through automation tools like Ansible. All key monitoring metrics and logs are shipped off-site and presented in beautiful dashboards.

But we live in an imperfect world where the Ansible playbooks aren't all written, dashboards can be insufficient and log aggregation services can be cumbersome to complete basic tasks.

Enter Xpanes, a parallel SSH tool

So when the perfect solutions aren't viable, sometimes xpanes can be a valuable tool to SSH to multiple servers in parallel and send input to all the windows at once. This is safe for read-only tasks like running htop or journalctl and in an emergency could also be used quickly make changes on multiple servers.

Basic syntax

The basic syntax for parallel SSH with xpanes looks like this:

xpanes --ssh server-1 server-2

There's no limit to the number of servers you access at once-- only the size of your monitor!

Tip: If you server names share a common prefix, you can shorter the command like this:

xpanes --ssh server-{1,2}

That will produce the same result as above.

How xpanes work

Xpanes using the tmux terminal multiplexer to split one terminal window into multiple smaller terminal windows. If you are not familiar with tmux or don't otherwise use it, that's OK. There's a few features of it that particularly useful with xpanes but you don't need to learn it in detail.

Making parallel changes safer

Making changes in parallel to redundant servers can spell disaster. If the change is broken, both servers break at the same time, erasing the benefit of having redundancy in the first place. One way to avoid this while using xpanes is with the "zoom" feature of Tmux, where you can zoom into a single window so it's the only one that receives the input. When you are done, the same keyboard shortcut will toggle zooming again so return to the parallel view and can then zoom into another window after selecting it with the mouse. I believe the default keybinding is "Control-b z" (neumonic: "z for zoom").

So the safer pattern to use: make the edit one server, check it, then change one or more other servers. xpanes may still be for other parts of the task, such as reviewing logs on both servers or reviewing files on both servers.

Selecting text with tmux

Tmux has its own clipboard system, making just copying text in xpanes harder than you expect it to be. Holding down Shift while selecting may help insure your terminal is selecting the text, not tmux.

Linux tip for xpanes: Create a .desktop file.

If you have some servers you frequently use xpanes to access because your life is frequently not perfect, on Linux you can create an XDG .desktop to launch xpanes from your desktop environment. Drop a file into ~/.local/share/applications with name like xpanes-servers.desktop. Here's an example. In this example, I set the background of the terminal to shade of red to signal that parallel SSH can be dangerous.

Update the name, comment, server names and terminal app to suit you.

[Desktop Entry]
Name=Xpanes servers
Comment=Parallel SSH to Servers
Exec=foot -o 'colors.background=3a0000' -e xpanes --ssh server-1 server-2
# Since we are calling foot explicity, don't launch from terminal