Bash script that just accepts an SSH handshake

Solution 1:

Use ssh-keyscan:

ssh-keyscan is a utility for gathering the public SSH host keys of a number of hosts. It was designed to aid in building and verifying ssh_known_hosts files.

ssh-keyscan -H ip >> ~/.ssh/known_hosts

You might first want to remove the address to avoid duplicates:

ssh-keygen -R ip