ssh-keyscan to fetch the public key. I have the following commands in a setup script I use:
ssh-keyscan -H $host,$ip4 >> ~/.ssh/known_hosts
ssh-keyscan -H $host >> ~/.ssh/known_hosts
ssh-keyscan -H $ip4 >> ~/.ssh/known_hosts
Refer to the man page. I'm including the security section below:
Security: If an ssh_known_hosts file is constructed using ssh-keyscan without verifying the keys, users will be vulnerable to man in the middle attacks. On the other hand, if the security model allows such a risk, ssh-keyscan can help in the detection of tampered keyfiles or man in the middle attacks which have begun after the ssh_known_hosts file was created.