Skip to content
shellhacks.dev
Network

Skip SSH Host Key Checking for a Throwaway VM

Skip host key prompts for disposable machines with StrictHostKeyChecking no and UserKnownHostsFile /dev/null in a Host block. accept-new is the safer middle ground.

1 min read
Summarize in AI

You rebuild test VMs all the time, and ssh keeps stopping with a changed host key warning or an unknown host prompt.

Shell
cat > cfg <<'EOF'
Host vm-*
  StrictHostKeyChecking no
  UserKnownHostsFile /dev/null
  LogLevel ERROR
Host lab-*
  StrictHostKeyChecking accept-new
EOF
for h in vm-test lab-1 prod; do
  echo "== $h"
  ssh -F cfg -G "$h" | grep -E '^(stricthostkeychecking|userknownhostsfile|loglevel) '
done
Text
== vm-test
stricthostkeychecking false
loglevel ERROR
userknownhostsfile /dev/null
== lab-1
stricthostkeychecking accept-new
loglevel INFO
userknownhostsfile /root/.ssh/known_hosts /root/.ssh/known_hosts2
== prod
stricthostkeychecking ask
loglevel INFO
userknownhostsfile /root/.ssh/known_hosts /root/.ssh/known_hosts2

A Host vm-* block applies the settings only to names that match the pattern, and ssh -G confirms that vm-test gets stricthostkeychecking false, a null known-hosts file and quiet logging, while prod keeps the default ask. accept-new trusts a host the first time it is seen and still refuses a changed key. See ssh_config.

Turning checking off removes the protection against a man in the middle, so keep it to machines on a trusted network that you recreate on purpose. Never put it in a Host * block. accept-new needs OpenSSH 7.6 or later.

Share

More snippets

Get new posts by email

One email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.