Guest blogger: Andrew Mallett

The Urban Penguin

I have blogged on using SSH before and setting up public key authentication for your administrators but now let's take this further and look at using SSH with the command screen to allow multiple sessions at the same time. Or, in simple terms, running the same command across many servers simultaneously executed from a central point.

Setup SSH Public key Authentication

We do not want to have to put in a password every time we authenticate to a server so we need to generate key-pairs for our admin account and copy the public key to each server we will manage. You can use the command ssh-keygen to crate the key pairs and ssh-copy-id to copy the public key. With this in place we can then use key authentication rather than password based authentication when connecting to the managed servers

Screen

The command screen will allow you to run a command simultaneously, an easy way to set it to run across many servers is to edit your .screenrc ( which should be created in your linux home directory ) . Each time you run the command screen this file is executed.
screen -t da1 ssh root@192.168.1.1 $CMDLINE

If this above line is in the .screenrc file. Each time screen runs it will connect via ssh to da1 and execute whatever command string is in the variable $CMDLINE. You could extend it to:
screen -t da1 ssh root@192.168.1.1 $CMDLINE
screen -t da2 ssh root@192.168.1.2 $CMDLINE
screen -t da3 ssh root@192.168.1.3 $CMDLINE
to manage more servers.

Then just populate the variable:
export CMDLINE="tar -czf /root/etc.tgz /etc"
and run screen. Simple and clean a back of the /etc directory on your three servers.

Linux Training