Just encountering this problem, here is how I approached it:
Over time, I copy files mechanically through
ssh-keyscan server-name >> ~/.ssh/known_hosts
gave me duplicate entries in .ssh / known_hosts.
Other manual methods required me to create a .ssh directory does not exist yet, etc.
I decided to just let ssh handle this:
ssh -o StrictHostKeyChecking=no server-name ls
The -o StrictHostKeyChecking=no automatically answers yes to
The authenticity of host 'server-name (12.345.678.900)' can't be established. RSA key fingerprint is XXXXXXX. Are you sure you want to continue connecting (yes/no)?
message (enter here all warnings about an accidental connection to computers that you do not know).
The ls is just a downy command that will be executed and cause SSH to disconnect after completion. You can change it to any fluff command that you like.
ssh will take care of creating a .ssh dir (if necessary), adding only one copy of the key, etc.
Platform: macOS 10.14
source share