ClusterSSH: Control Multiple SSH Sessions
ClusterSSH is a group SSH administration tool. It is used to control number of xterm windows via single Administration console to allow commands to run on multiple servers over an SSH connection. Sometimes, you may have chances to enter same command on many servers. To do that, you have to login to each server and should enter the command on each server which is time consuming process. Using ClusterSSH, the commands typed in the Administration Console window will replicate to all servers. In simple words it is an excellent tool for making the same change on multiple servers at the same time.
The ‘cssh’ command opens an administration console and an xterm to all specified hosts. Any text typed into the administration console is replicated to all windows.
Operating System Used: Ubuntu 14.04 LTS #Compatible with all known OS.
Installation
[js]$ sudo apt-get update
$ sudo apt-get install libx11-dev clusterssh[/js]
Use cases of ClusterSSH
a. Connecting to more than one server using single user
[js] $ cssh -l <user> 5.5.5.5 4.4.4.4 3.3.3.3 2.2.2.2 [/js]
Note: Recommendation is to use separate workspace for it.
b. Connecting to servers with different username
[js]$ cssh user1@5.5.5.5 user2@4.4.4.4 user3@3.3.3.3[/js]
[ However, this will require entering password on each window]
c. If you want to run a command on a single server, just select that window and start working. After you are done, just return back to Administration Console.
d. Using configuration file(s) :
Another way to run multiple SSH session is put the address of each server and SSH arguments in CSSH configuration file. There are two types of configuration files. First is global configuration file. This file is located in /etc/clusters. Here we can create a group of our servers. Second is .clusterssh/config which located in users home directory. Here, we can define different SSH arguments we would like to use against our servers. Note that only single SSH Argument link (the first one) will be used at once.
Open SSH configuration file:
[js]$ vim ~/.clusterssh/config [/js]
Add this line anywhere you want, but it should be declared only once in the file
ssh_args= -x -o ConnectTimeout=10 -l ubuntu -p22
In case you want to connect with keys here would be your entry:
ssh_args= -x -o ConnectTimeout=10 -i <path/to/your/key> -l ubuntu -p22
Open Server Configuration file:
[js] $ vim /etc/clusters [/js]
##Server Groups database 5.5.5.5 4.4.4.4 3.3.3.3 2.2.2.2
Now just run below command
[js]$ cssh database[/js]
And you will get the same x-term windows with a main Administration window.
e. Restricting Command flow to specific servers for a while.
If you don’t want to forward your command to all servers, you can disable host(s) that you want to exclude. Just click Hosts menu in Administration Console and choose which server you want to exclude. This way your command written on Administration console will be forwarded to all hosts except the excluded ones. This is reverse of use case ‘c’.
Note:
When you execute the wrong commands, it will impact to all the servers. Please make sure that you’re typing a correct command before hitting Enter button. We can anytime use man cssh or cssh -h to display its manual page and explore more detail.