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 →
- Store the key as an SSH credential in the team's prod folder only.
- Use
sshagent(['prod-deploy-key']) { sh 'ssh -o StrictHostKeyChecking=yes deploy@host ...' }with known hosts pinned in the repo or image. - Limit the key on the server side (
command=inauthorized_keys, non-root user,from=agent IPs). - 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.
More on Credentials & security
What credential types does Jenkins support out of the box?BeginnerWhat is the difference between Global and System credential scope?IntermediateHow do folder-scoped credentials help multi-team controllers?IntermediateHow does Jenkins mask secrets in logs and what are its limits?AdvancedWhat authorization strategies are available?IntermediateWhat are the key permissions to understand in matrix auth?Intermediate