Using ssh
command line (OpenSSH), can I specify the server's host key fingerprint?
This is possible with winscp.com using (e.g.) -hostkey="ssh-rsa 2048 AA:BB:CC...etc
I have read the man page a couple times, I apologize if I've missed the obvious there.
I do not want to just auto accept a host key, and I don't want to require the user to update their known_hosts
, but rather specify the host key in some form on the command line.
Best Answer
There's no command-line option in OpenSSH to pass a host key fingerprint.
Though you can use a temporary file (with the same format as the
known_hosts
) and make thessh
use that using the-o UserKnownHostsFile
:See the
ssh
(for the-o
) and thessh_config
(for theUserKnownHostsFile
) man pages.You may also consider using the
StrictHostKeyChecking yes
.As suggested on Auto accept rsa key fingerprint from command line, you could write a small script that would allow you to achieve that:
If you call the script
ssh_known_host
, you could use it, passing the key as the first argument:Btw, do not try to use
<()
shell construct withUserKnownHostsFile
, like this:It won't work. Possibly because the fd created by
<()
can be read only once, whilessh
reads the file repeatedly.