Skip to content

Instantly share code, notes, and snippets.

@mgedmin
Created March 14, 2014 12:59
Show Gist options
  • Save mgedmin/9547214 to your computer and use it in GitHub Desktop.
Save mgedmin/9547214 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'
@drauschenbach
Copy link

We're not self-hosting Git so you can remove those two big sections. The Jenkins master should push the necessary keys along with the job.

@inl-pd-autotest
Copy link

adduser for me has no --group, but it has --groups and of course it requires at least 1 group to be listed, which one does jenkins slave need?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment