Saurav Ojha
Saurav Ojha

Reputation: 155

SSH from Jenkins without using Plugin

I want to run a few commands on a remote machine by doing an SSH from my Jenkins server. However, I cant use SSH Plugin as it is a Corporate Jenkins(Multi-Tenanted).

Currently, I am creating a user for the remote machine with the SSH keys by using the 'My Credentials' section of Jenkins and adding the same credentials in the Jenkins Build Environment by checking 'SSHAgent' checkbox.

I use the command 'ssh user_name@ip ', but it seems to be stuck at that step. Would be a great help if someone helps me figure this out.

Upvotes: 2

Views: 12950

Answers (2)

mahes wari
mahes wari

Reputation: 91

Go to Jenkins → Manage Jenkins → Configure System and check for SSH Remote hosts and give the hostname, number and add the username and password of remote hosts

SSH remote hosts

Go to your jenkins job → Configure → Build → enter image description here

If SSH Remote hosts are not available in Manage jenkins → Configure System → Install plugin in jenkins https://wiki.jenkins.io/display/JENKINS/SSH+plugin

Upvotes: 3

Anurag Arya
Anurag Arya

Reputation: 111

Please use below commands to enable ssh from jenkins to remote host/machine.

first enable ssh password less.

please generate rsa key in your jenkins server/linux box and add this public IP into your remote host under .ssh directory in authorized_keys file ( if .ssh dir or authorized_key file is not present, please create) after change permission of this file to 640 ( chmod 640 authorized_key).

it will enable you to ssh without password from jenkins box to remote host. after this you can execute shell command from jenkins ( add build step / execute shell) and enter below command

ssh user_name@IP_address_of_remote_host

as per requirement you can add more commands after ssh in quotes " " and separate all command by a semicolon

Upvotes: 1

Related Questions