为 Jenkins 生成 SSH Key
为 Jenkins 部署生成专用 SSH key(与默认 id_rsa 区分,便于在 Jenkins 凭据中单独管理)。
ssh-keygen -t rsa
# 指定独立文件名,避免覆盖默认 key
Enter file in which to save the key (~/.ssh/id_rsa): ~/.ssh/id_rsa_jenkins
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
# 生成:~/.ssh/id_rsa_jenkins(私钥)、~/.ssh/id_rsa_jenkins.pub(公钥)
- 公钥(
id_rsa_jenkins.pub):部署到目标服务器的~/.ssh/authorized_keys,或填到 Git 仓库的 Deploy Key。 - 私钥(
id_rsa_jenkins):填到 Jenkins 的「凭据(Credentials)→ SSH Username with private key」中。
⚠️ 私钥务必妥善保管,不要提交到代码仓库或公开分享。
原文链接:https://www.ssssmy.com/notes/wei-jenkins-sheng-cheng-ssh-key