Template script:
$ PUB="paste your pubkey here"
$ for h in %LIST OF HOSTS%; do echo -n "$h -> " && ssh ec2-user@${h} "if grep -Fxq \"${PUB}\" .ssh/authorized_keys; then echo 'the pubkey already exists'; else echo \"${PUB}\" >> .ssh/authorized_keys && echo \"the pubkey was added\"; fi"; done
Example usage:
$ PUB='ssh-rsa XXXXXXXXXXXXXXXXXXXXX== foo'
$ for h in dev1 dev2 dev3; do echo -n "$h -> " && ssh ec2-user@${h}.mydomain.com "if grep -Fxq \"${PUB}\" .ssh/authorized_keys; then echo 'the pubkey already exists'; else echo \"${PUB}\" >> .ssh/authorized_keys && echo \"the pubkey was added\"; fi"; done