Interview Prep/Jenkins/Credentials & security

A team wants to SSH into production servers from pipelines. How do you implement it safely?

IntermediateScenarioCredentials & security
Answer

Situation read → SSH keys in CI are high value.

What I'd do →

  1. Store the key as an SSH credential in the team's prod folder only.
  2. Use sshagent(['prod-deploy-key']) { sh 'ssh -o StrictHostKeyChecking=yes deploy@host ...' } with known hosts pinned in the repo or image.
  3. Limit the key on the server side (command= in authorized_keys, non-root user, from= agent IPs).
  4. Prefer SSH certificates with short validity issued by Vault per build.

Why → Narrow key capabilities and short lifetimes reduce impact of leaks.

Interview tip → Never disable host key checking in pipelines.

All Jenkins questions Roadmap: Jenkins

More on Credentials & security