<p>Connecting a node to Jenkins through a terminal only is a two step process.</p>

<p>First, you should ssh into into your node machines and set them up with the following steps:</p>

<ol>
<li><p>Make a jenkins user shell:  <code>sudo adduser jenkins --shell /bin/bash</code></p></li>
<li><p>Create the directory after switching to the jenkins user:  <code>mkdir /home/jenkins/jenkins_slave</code></p></li>
<li><p>Create your SSH credentials to be used in the following bash script.</p></li>
</ol>

<p>Then, once your nodes are set up, you will need to connect to your jenkins machine and run bash script such as this <a href="https://gist.github.com/sergeyhush/4e892837cf5c31c3d242" rel="nofollow noreferrer">one</a> to connect your nodes to your master:</p>

  

<pre><code>#!/bin/bash

JENKINS_URL=$1
NODE_NAME=$2
NODE_SLAVE_HOME='/home/build/slave'
EXECUTORS=1
SSH_PORT=22
CRED_ID=$3
LABELS=build
USERID=${USER}

cat &lt;&lt;EOF | java -jar ~/bin/jenkins-cli.jar -s $1 create-node $2
&lt;slave&gt;
  &lt;name&gt;${NODE_NAME}&lt;/name&gt;
  &lt;description&gt;&lt;/description&gt;
  &lt;remoteFS&gt;${NODE_SLAVE_HOME}&lt;/remoteFS&gt;
  &lt;numExecutors&gt;${EXECUTORS}&lt;/numExecutors&gt;
  &lt;mode&gt;NORMAL&lt;/mode&gt;
  &lt;retentionStrategy class="hudson.slaves.RetentionStrategy$Always"/&gt;
  &lt;launcher class="hudson.plugins.sshslaves.SSHLauncher" plugin="ssh-slaves@1.5"&gt;
    &lt;host&gt;${NODE_NAME}&lt;/host&gt;
    &lt;port&gt;${SSH_PORT}&lt;/port&gt;
    &lt;credentialsId&gt;${CRED_ID}&lt;/credentialsId&gt;
  &lt;/launcher&gt;
  &lt;label&gt;${LABELS}&lt;/label&gt;
  &lt;nodeProperties/&gt;
  &lt;userId&gt;${USERID}&lt;/userId&gt;
&lt;/slave&gt;
EOF
</code></pre>

CC BY-SA 3.0
2017-03-02T05:16:41.110Z
It should be noted that this does not really require connecting with SSH to the node, since you can run the CLI call remotely.
Assaf Lavie
CC BY-SA 3.0
2017-03-01T08:49:15.780Z
2017-03-01T08:49:15.780Z
avi
<p>I'd like to connect a build node to the Jenkins master. Ideally without using a web browser or being in front of the physical machine. What would be the easiest way to achieve that?</p>

<jenkins><linux>
How to connect a build node to a Jenkins master?
kenorb
# How to connect a build node to a Jenkins master?

(Asked by: username_0 on 2017-02-28)

I'd like to connect a build node to the Jenkins master. Ideally without using a web browser or being in front of the physical machine. What would be the easiest way to achieve that?

**Tags:** jenkins, linux


---

## 1 answers

### Answer by username_1 on 2017-03-01. Score: 3 | Accepted answer

Connecting a node to Jenkins through a terminal only is a two step process.
First, you should ssh into into your node machines and set them up with the following steps:

Make a jenkins user shell:  sudo adduser jenkins --shell /bin/bash
Create the directory after switching to the jenkins user:  mkdir /home/jenkins/jenkins_slave
Create your SSH credentials to be used in the following bash script.

Then, once your nodes are set up, you will need to connect to your jenkins machine and run bash script such as this one to connect your nodes to your master:
#!/bin/bash

JENKINS_URL=$1
NODE_NAME=$2
NODE_SLAVE_HOME='/home/build/slave'
EXECUTORS=1
SSH_PORT=22
CRED_ID=$3
LABELS=build
USERID=${USER}

cat <
  ${NODE_NAME}
  
  ${NODE_SLAVE_HOME}
  ${EXECUTORS}
  NORMAL
  
  
    ${NODE_NAME}
    ${SSH_PORT}
    ${CRED_ID}
  
  ${LABELS}
  
  ${USERID}

EOF

> **Comments:**
> **username_2**: It should be noted that this does not really require connecting with SSH to the node, since you can run the CLI call remotely.  

---

