Automate pushing of ssh-copy-id to multiple servers

This is a follow-up of the writeup of  Tools to automate ssh-copy-id to remote servers. The Server OS used is CentOS 6.2. If you are automating scripts, you may have to modify the default settings SSH first.

I think you probably would have encounter the yes/no question below when trying to ssh into a remote server.

The authenticity of host ' (' can't be established.
RSA key fingerprint is 8d:e7:92:ef:86:1a:fb:4a:01:00:6a:fc:8c:23:ed:15.
Are you sure you want to continue connecting (yes/no)?

To rectify the issue, you can do at server levels /etc/ssh/ssh_config

# vim /etc/ssh/ssh_config
#  StrictHostKeyChecking ask
StrictHostKeyChecking no

Alternatively, you can Or at local account level at ~/.ssh/config

$ vim ~/.ssh/config

Add the following lines

StrictHostKeyChecking no

You may want to revert back to the default settings of StrictHostKeyChecking after you have push your keys if you have configure of /etc/ssh/ssh_config or remove the 2 lines above if you are doing with the local account

Next you can use a simple bash scripts. I’m not comfortable in using the password in text. So make sure only you can view the file.

for i in 'cat my_hosts_list'    
       sshpass -p 'server_password' ssh-copy-id admin@${i}

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.