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-authorityinknown_hosts), - or populate
known_hostsfrom 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.
More on Security and Secrets
How do you set up a secure automation user and SSH access?BeginnerHow do you give the automation user sudo with least privilege?IntermediateWhat are the alternatives to Ansible Vault for secrets, and when do you use them?IntermediateHow do you read AWS Secrets Manager and SSM parameters in a playbook?IntermediateHow do you integrate HashiCorp Vault with Ansible?AdvancedHow do you stop secrets from leaking into logs and output?Beginner