Answers: <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>
  
Answers: CC BY-SA 3.0
Answers: 2017-03-02T05:16:41.110Z
Answers: It should be noted that this does not really require connecting with SSH to the node, since you can run the CLI call remotely.
Answers: Assaf Lavie
Answers: CC BY-SA 3.0
Answers: 2017-03-01T08:49:15.780Z
Answers: 2017-03-01T08:49:15.780Z
Answers: avi
Body: <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>
  
Tags: <jenkins><linux>
Title: How to connect a build node to a Jenkins master?
UserDisplayName: kenorb
ThreadText: # 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:
  
  1. Make a jenkins user shell: `sudo adduser jenkins --shell /bin/bash`
  2. Create the directory after switching to the jenkins user: `mkdir /home/jenkins/jenkins_slave`
  3. 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](https://gist.github.com/sergeyhush/4e892837cf5c31c3d242) 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 <<EOF | java -jar ~/bin/jenkins-cli.jar -s $1 create-node $2
  <slave>
    <name>${NODE_NAME}</name>
    <description></description>
    <remoteFS>${NODE_SLAVE_HOME}</remoteFS>
    <numExecutors>${EXECUTORS}</numExecutors>
    <mode>NORMAL</mode>
    <retentionStrategy class="hudson.slaves.RetentionStrategy$Always"/>
    <launcher class="hudson.plugins.sshslaves.SSHLauncher" plugin="ssh-slaves@1.5">
      <host>${NODE_NAME}</host>
      <port>${SSH_PORT}</port>
      <credentialsId>${CRED_ID}</credentialsId>
    </launcher>
    <label>${LABELS}</label>
    <nodeProperties/>
    <userId>${USERID}</userId>
  </slave>
  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.  
  
  ---
  
  