how to setup ssh keys for jenkins to publish via ssh

前端 未结 3 780
我寻月下人不归
我寻月下人不归 2020-12-13 00:26

Jenkins requires a certificate to use the ssh publication and ssh commands. It can be configured under \"manage jenkins\" -> \"Configure System\"-

3条回答
  •  甜味超标
    2020-12-13 01:22

    You don't need to create the SSH keys on the Jenkins server, nor do you need to store the SSH keys on the Jenkins server's filesystem. This bit of information is crucial in environments where Jenkins servers instances may be created and destroyed frequently.

    Generating the SSH Key Pair

    On any machine (Windows, Linux, MacOS ...doesn't matter) generate an SSH key pair. Use this article as guide:

    • GitHub: Generating a new SSH key and adding it to the ssh-agent (you can skip the section "Adding your SSH key to the ssh-agent")

    On the Target Server

    On the target server, you will need to place the content of the public key (id_rsa.pub per the above article) into the .ssh/authorized_keys file under the home directory of the user which Jenkins will be using for deployment.

    In Jenkins

    Using "Publish over SSH" Plugin

    Ref: https://plugins.jenkins.io/publish-over-ssh/

    Visit: Jenkins > Manage Jenkins > Configure System > Publish over SSH

    • If the private key is encrypted, then you will need to enter the passphrase for the key into the "Passphrase" field, otherwise leave it alone.
    • Leave the "Path to key" field empty as this will be ignored anyway when you use a pasted key (next step)
    • Copy and paste the contents of the private key (id_rsa per the above article) into the "Key" field
    • Under "SSH Servers", "Add" a new server configuration for your target server.

    Using Stored Global Credentials

    Visit: Jenkins > Credentials > System > Global credentials (unrestricted) > Add Credentials

    • Kind: "SSH Username with private key"
    • Scope: "Global"
    • ID: [CREAT A UNIQUE ID FOR THIS KEY]
    • Description: [optionally, enter a decription]
    • Username: [USERNAME JENKINS WILL USE TO CONNECT TO REMOTE SERVER]
    • Private Key: [select "Enter directly"]
    • Key: [paste the contents of the private key (id_rsa per the above article)]
    • Passphrase: [enter the passphrase for the key, or leave it blank if the key is not encrypted]

提交回复
热议问题