Interview Prep/Ansible/Security and Secrets

Should you disable `host_key_checking` in production?

BeginnerProductionSecurity and Secrets
Answer

No. Turning it off removes protection against man-in-the-middle attacks and it is only acceptable in throwaway lab environments. In cloud environments where hosts are ephemeral, the practical approach is to keep it on and handle keys properly:

  • bake the host key trust through an SSH CA (@cert-authority in known_hosts),
  • or populate known_hosts from a trusted source (for example EC2 console output) during provisioning,
  • or avoid SSH host keys by using SSM Session Manager.

Disabling checks silently in ansible.cfg often survives from a lab into production, so lint for it.

All Ansible questions Roadmap: Ansible

More on Security and Secrets