I assume you have an user with username as user1
in all the 200 machines.
First, create a public ssh key on your machine, (say machine 1)
ssh-keygen -t rsa
You will be asked for a passphrase which you will be asked to enter the first time you run any ssh command after each login. This means that for multiple ssh
or scp
commands, you will only have to enter it once. Nevertheless, you can leave it empty to have completely passwordless access.
If you are in a network, all your IP addresses would be available in /etc/hosts
.
You can get the list of IP addresses or host names and save it in a file with just the hostnames alone.
My IPlistfile.txt is as below.
192.168.1.11
192.168.1.12
Once you have generated your public key, copy it over (as user1
) to each computer in your network.
while read ip; do
ssh-copy-id -i ~/.ssh/id_rsa.pub user1@$ip
done < IPlistfile.txt
You will have to manually enter the password for each IP (unless you use one of the solutions below for this step as well) but once you've done that, you will be able to run the script without using passwords in all those machines.
Now, you can have a script to ssh to all the machines and logging out periodically.
while read ip; do
ssh user1@$ip
exit
done < IPlistfile.txt
The above script could be placed in a cronjob
and could be run periodically to login and logout of servers as you wish without locking the user account.
Please refer to the answer to my question titled script to automate scp in a network and it will give you more ideas.