Welcome to thatlinuxbox.com Thursday, July 25 2024 @ 06:57 PM UTC

Cluster SSH

  • Wednesday, January 25 2012 @ 12:05 AM UTC
  • Contributed by:
  • Views: 10,336
Linux, Open Source, and Tech Stuff

  • Google Plus
  • Facebook
  • Twitter
  • Reddit
  • LinkedIn
  • Digg

ClusterSSH is a nice tool for manipulating multiple *nix machines simultaneously. For example, if I want to run some commands on two Linux machines named server1 and server2, I could:

# cssh server1 server2

And I will get two xterm windows that I can control simultaneously by typing into the cssh command window. Since cssh will send keystrokes to both servers, any series of commands can be run, including editing files, etc. I have found that my daily patterns of behavior make cssh preferable to similar tools such as pdsh. Also, cssh uses very similar options syntax to the ssh command, so I don't have to remember different options (I frequently use -l and -p).

I might want to tail the logs on all of the machines in the cluster, but then focus in on one particular machine after I have identified a particular cluster node of interest. Similarly, I might work out a long command line on a single node before running it on the rest of the machines via the cssh command window.

In Debian and Ubuntu, cssh can be installed with:

# sudo apt-get install clusterssh

Cluster SSH is also available for Mac OS X (http://code.google.com/p/csshx/).

A clusterssh package seems to be working its way into Red Hat flavors via Extras or 3rd party repos such as rpmforge.

After running cssh for the first time, you will have a .csshrc file in your home directory. This file can be tweaked in various ways to make connecting to groups of machines easier. To save a group of machines into a list that you can re-use, cssh can use a plain text cluster file.

To use a cluster file:




Step 1: Create a file named .clusters that contains your list of server groups. The format of the file is just a friendly name for a cluster followed by all of the machines that you want to connect as part of that cluster, with white space in between.

For example, my .clusters file looks something like:

prod_servers server1 server2 server3 server4

test_servers testserver1 testserver2

Step 2: Modify .csshrc to tell cssh to use the clusters file.


Now that I have a cluster defined, I can connect to my prod servers all at once by running:

# cssh prod_servers

In my example case, this would open four xterms to the four servers. If I type into the cssh command window the text will go to all four xterms. If I only want to run a command on one of them, I just click on the particular xterm to give it focus and it behaves like a normal individual xterm.

I have found cssh to be a valuable utility in my sysadmin toolbox.

Cluster SSH | 0 comments | Create New Account

The following comments are owned by whomever posted them. This site is not responsible for what they say.

User Functions



thatlinuxbox.com is the home of Dan Stoner's Personal Blog, Photos, and More (opinions, rants, techno-babble, and possibly a few useful tidbits of knowledge).

Questions or Comments about this site? Contact danstoner _ at _ gmail.com.

RSS Feed for this blog

Other places to find me on the web:




Support This Site

If you like something that you find on this site, please consider making a purchase through one of the links below or sending me an item from my Amazon Wish List.

The Clymb

Awesome VPS hosting by Linode.com