Tuesday, August 29, 2023

SSH Remote Hosts setup in Jenkins

Jenkins


Login to Jenkins instance: http://devops/8080
Click on Manage Jenkins -> Configure System -> scroll down to "SSH remote hosts" section

Enter the Hostname, default port is 22
Credentials -> Click on Add -> Jenkins ->


Enter ID, Description, Username and then select Private Key and choose Enter directly, click on Add

To get the private ssh keys, login to the Hostname you entered in the previous screen/step and create .ssh folder under $HOME and generate rsa keys under $HOME/.ssh directory

ssh-keygen -t rsa


choose the directory and just hit enter twice when asked for a passphrase


cat id_rsa.pub >> ~/.ssh/authorized_keys
(on the host)

chmod 700 ~/.ssh

chmod 600 ~/.ssh/authorized_keys ~/.ssh/id_rsa


Then copy the Private SSH key (id_rsa contents) and paste it back in the Add Credentials page of Jenkins -> Click on Add -> Click on Save


Go to Jenkins home page -> Click on New Item -> Enter a Item name -> Freestyle project -> click ok


Go directly to Build section -> select Execute shell script on remote host using ssh

Select the SSH Site

Under the command section -> add the commands

Click on Save

Click on Build Now

View Console Output