How to configure private key generated by PuTTYGen in Jenkins

  Reading Time:

Assume you have already create the public and private key using PuTTYGen

Private and public key

We need to connect Jenkins to the cloud server using this private SSH key , we assume that the public key is added to the server and is not within the scope of this article

Login to Jenkins and navigate to manage Jenkins

Click configure system menu

 

 

Scroll to‘Publish over SSH’  section

'Publish to SSH' section in Jenkins UI

 

Click  ‘Add’  button to add a new server SSH settings under ‘Publish over SSH’

Click 'Add' button to add the new ssh server

 

Click  ‘Advanced’  button to see the SSH and Authentication options

Click ‘Advanced’ button to see authentication options

 

Click ‘Advanced’ button to add SSH key

Enter SSH server information

   

Now go to PuTTYGen and load the existing private ppk file using import option

Import private key
Private key to be loaded

 

It will ask for the passphrase that was given during key generation(if not given we will not see this screen )

Enter private key passphrase

 

The SSH key will be loaded and we will see the public key that corresponds to the private key and now we need to convert this to open ssh format that is understood by Jenkins

Public key shown under Key section

 

Export key to OpenSSH format

Export to OpenSSH format

   

Save the open ssh key file to‘some-filename-open-ssh-format’

Save the converted format

 

We will see one additional file created in open ssh format and lets see its content and format

Converted openssh format shown in the folder

 

The content of the private open ssh format key file

OpenSSH format key content 

 

Lets paste this content to Jenkins.

  1. Add the SSH key passphrase in the ‘Passphrase/Password ’ field
  2. RSA key open ssh format inside ‘Key’ field
Add key to Jenkins

   

Lets test if we are able to connect , click the ‘Test Configuration’ button

Test configuration in Jenkins

 

Success message indicates that connection was successful , now we can publish over shh from Jenkins

Success message shown

 

If incorrect ssh key then connection will fail because of Authentication failure and we we will see this kind of a message

jenkins.plugins.publish_over.BapPublisherException: Failed to connect and initialize SSH connection. Message: [Failed to connect session for config [DO-cosmos-api-server-spring-boot-1]. Message [USERAUTH fail]]
Error message if not able to connect to server

 

If incorrect ssh key format then we will get the error message  shown below

jenkins.plugins.publish_over.BapPublisherException: Failed to add SSH key. Message [invalid privatekey: [B@3ef89687]
Error message if key is incorrect

 

Summary

We have seen how to create a open ssh format file using PuttyGen tool to configure Jenkins‘Publish over SSH’ for our cloud server connection

Setup SonarQube on Ubuntu 18.04

Hardware Requirements Source : https://docs.sonarqube.org/latest/requirements/requirements/SonarQube server requires at least 2GB of RAM to run efficiently and 1GB of free RAM...

App & Geek   Never miss a story from App & Geek, get updates in your inbox.