Interview Prep/Shell Scripting/Scenarios: deployments, user management and fleet operations

A CI pipeline deploys to servers over SSH. The first run fails with `Host key verification failed.` A teammate suggests `StrictHostKeyChecking=no`. What do you do?

IntermediateScenarioScenarios: deployments, user management and fleet operations
Answer

Situation read → The runner has no known_hosts entry. Disabling checking removes protection against man-in-the-middle attacks on your deploy path.

What I'd do →

  1. Store the servers' host keys as a CI variable (collected once from a trusted source, for example the instance's console output or your config management), and write them in the job:
    install -d -m 0700 ~/.ssh
    printf '%s\n' "$KNOWN_HOSTS" > ~/.ssh/known_hosts
    chmod 0644 ~/.ssh/known_hosts
    
  2. Load the deploy key from a secret with ssh-agent, never write it with loose permissions.
  3. Use -o BatchMode=yes so failures are immediate.
  4. For dynamic fleets, use SSH host certificates signed by your CA, and @cert-authority in known_hosts.

Why → Host key checking is the only thing proving you are talking to your server and not an attacker.

Interview tip → Refusing StrictHostKeyChecking=no politely, with an alternative, is the answer interviewers want.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: deployments, user management and fleet operations