How to add ssh keys to multiple hosts


  • list.txt: list of hosts
  • ~/.ssh/ keys to add

Bash script

for ip in `cat list.txt`; do
    sshpass -p "yourpassword" ssh-copy-id -o StrictHostKeyChecking=no -i ~/.ssh/ [email protected]$ip


  • sshpass pass your password to the ssh prompt
  • -o StrictHostKeyChecking=no ignores the “host identity not established” prompt, allowing sshpass to do its job

How to execute

sudo apt install -y sshpass
chmod +x


Leave a Reply

Your email address will not be published. Required fields are marked *

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