If your goal is to connect to a predetermined host in a clean enviroment (ex. a ci pipeline) you can pregenerate the known_hosts
file:
First in your enviroment:
$ ssh -oUserKnownHostsFile=known_hosts example.com
The authenticity of host 'example.com (2606:2800:21f:cb07:6820:80da:af6b:8b2c)' can't be established.
ED25519 key fingerprint is SHA256:/IJSyNxVg5lnxYua11Wlm2G2fBMifdrkvT94o4vzlPc=.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'example.com' (ED25519) to the list of known hosts.
After confirming, you can then use that known_hosts
file to verify the authenticity of the host without user interaction.
$ ssh -oUserKnownHostsFile=known_hosts example.com
y
to save some time, and it complains:Please type 'yes' or 'no':
(hmph)