Skip to content

Instantly share code, notes, and snippets.

@aloha1003
Forked from mgedmin/gist:9547214
Created July 28, 2016 15:43
Show Gist options
  • Save aloha1003/cb074b94a625e6790ccbde48fde2f5e2 to your computer and use it in GitHub Desktop.
Save aloha1003/cb074b94a625e6790ccbde48fde2f5e2 to your computer and use it in GitHub Desktop.
Setting up a Jenkins slave on Linux
# This is how you add a Jenkins slave
# On master:
sudo -u jenkins -H ssh-keygen
# On slave
adduser --system --group --home=/var/lib/jenkins-slave --no-create-home --disabled-password --quiet --shell /bin/bash jenkins-slave
install -d -o jenkins-slave -g jenkins-slave /var/lib/jenkins-slave
install -d -m 700 -o jenkins-slave -g jenkins-slave /var/lib/jenkins-slave/.ssh
vi /var/lib/jenkins-slave/.ssh/authorized_keys
copy jenkinsmasterhost:/var/lib/jenkins/ssh/id_rsa.pub
# On master
sudo -u jenkins -H ssh jenkins-slave@muskatas
# remember the host key
# Now you can add an SSH slave through the Jenkins web UI, it'll download all the Java .jars automatically
# (you may need to sudo apt-get install openjdk or something on the slave machine)
# To allow the slave to get access to git repos on mygitserver, run this on the slave machine:
sudo -u jenkins-slave -H ssh-keygen
# On mygitserver
adduser --system --group --home=/var/lib/jenkins-slave --no-create-home --disabled-password --quiet --shell /usr/bin/git-shell jenkins-slave
install -d -o jenkins-slave -g jenkins-slave /var/lib/jenkins-slave
install -d -m 700 -o jenkins-slave -g jenkins-slave /var/lib/jenkins-slave/.ssh
vi /var/lib/jenkins-slave/.ssh/authorized_keys
copy /var/lib/jenkins-slave/ssh/id_rsa.pub from the slave machine
# On slave
sudo -u jenkins-slave -H ssh mygitserver
# remember the host key
sudo -u jenkins-slave -H git config --global user.name 'Jenkins'
sudo -u jenkins-slave -H git config --global user.email 'root@example.com'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment