Servers (and other SSH enabled devices like switches, routers and Raspberry Pis) multiply like rabbits in today’s cloud-ready world and sys admins often need to perform the same task on many remote server instances via SSH.  If this sounds familiar, then csshX (Cluster SSH for OS X) is your friend!
For example, restarting Apache on 4 machines takes just two steps. 1) Log in: csshX server1 server2 server3 server4 and 2) restart apache: service apache2 restart – so cool!

csshX will make an SSH connection to any number of servers, opening each in a separate terminal window. The tool neatly tiles all the connections and a red control terminal opens across the bottom of the screen. What you type into the red control terminal is sent to all the client terminals. Very nifty.
You can also select an individual client connection and work on that independently and then switch back to the control terminal for en masse control.

csshX utilizes the built in  OS X Terminal application but can be invoked from iTerm2 or whatever alternative terminal you might use. (iTerm2 is the way to go!)

Notes:

  • Easily install csshX with Homebrew, a great package manager for OS X.
  • Utilize SSH keys to facilitate secure logins.
  • apt-get install clusterssh to get cssh for your Linux Debian / Ubuntu desktop.
  • Toggle between master control and individual sessions by clicking on the respective Terminal window.
  • Edit /etc/clusters to make short tags to connect to many servers under one name – the list is space separated with the first word used as the tag and the following items as URLs.
    • For example the following line in /etc/clusters will enable you to connect to 5 servers by just running: csshx mylist
    • mylist server1.example.com server2.example.com server3.example.com server4.example.com server5.example.com
    • See below video for csshx configuration file example including aliases to make it simple to connect to groups of computers.

 

Below is a video screen capture example of csshX connecting via SSH to 16 Linux servers and sending the following commands to all 16 servers en masse:
(Note that instead of invoking csshx followed by all the server names, I could have used /etc/clusters to group the servers under one tag to save time.)

Launch Terminal (command + space bar -> start typing Terminal and hit enter.)

csshx server1 server2 server3 server4 server5 server6 (launch csshx with all the servers you want to control - use /etc/clusters to make this cleaner.)
ls -alh /tmp
vi /etc/resolv.conf
:q (to exit vi)
ping google.com
ctrl-c (to end the ping)
sync (because old habits die hard)
htop
q (to exit htop)
exit (to log off all sessions)

 

 

Sample csshx clusters config file – /etc/clusters

### VW Servers ###
ice-all proxy-gq1-1.icecream.co proxy-gq1-2.icecream.co proxy-gq1-3.icecream.co
ice-proxy proxy-gq1-1.icecream.co proxy-gq1-2.icecream.co proxy-gq1-3.icecream.co
api-fmt2 api-fmt2-1.virtualworld.com api-fmt2-2.virtualworld.com
api-sj1 api-sj1-1.virtualworld.com api-sj1-2.virtualworld.com
vc-misc api-tay.virtualworld.com blog.getcn.com
vc-db db-fmt1-1.virtual.com db-fmt2-1.virtual.com db-ir1-1.virtual.com
### OO Servers ###
oo-ubuntu sofa rind voetsek.zinkwazi.com bokke
### All Servers (Alias of all the aliases above) ###
all-servers ice-all ice-proxy api-fmt2 api-sj1 vc-misc vc-db oo-ubuntu