$hosts ="host1 host2 host3" # use ssh-keyscan to populate your "known_hosts" file first: ssh-keyscan $hosts >>~/.ssh/known_hosts # then append your key on the remote hosts: for h in $hosts do echo "*** copying key to $h ***" cat ~/.ssh/id_rsa.pub | ssh $h 'cat >>~/.authorized_hosts' done