Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

As far as I know the default ssh option StrictHostKeyChecking is set to ask so the first ssh connection seems like:

$ ssh host.example.com
The authenticity of host 'host.example.com (1.2.3.4)' can't be established.
RSA key fingerprint is 52:9b:0a:f1:e4:51:1b:96:8c:b7:96:7c:d3:d2:7d:9f.
Are you sure you want to continue connecting (yes/no)?
  • I'd like to automatically add host key for the first time assuming the possible security issue.
  • I'd like the host key to be used by any local user automatically (e.g. without any extra ssh command-line options).
share|improve this question

migrated from stackoverflow.com Mar 12 '13 at 9:50

This question came from our site for professional and enthusiast programmers.

1 Answer 1

I've read man ssh and man ssh_config and figured out the solution for this:

#!/bin/bash

SSH_KNOWN_HOSTS=/etc/ssh/ssh_known_hosts
[ -e $SSH_KNOWN_HOSTS ] || touch $SSH_KNOWN_HOSTS
for host in \
    host1.example.com \
    host2.example.com \
; do
    ssh-keygen -R $host -f $SSH_KNOWN_HOSTS
    ssh -q -o StrictHostKeyChecking=no -o BatchMode=yes -o UserKnownHostsFile=$SSH_KNOWN_HOSTS $host echo '' || true
done
chmod a+r $SSH_KNOWN_HOSTS

It works but seems hacky. Do you know a shorter way to do this ?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.