May 19, 2022•176 words
Connect Jenkins to Deployment Environment Servers with SSH Keys
The following are essential steps in connecting jenkins to a series of deployment servers, so Jenkins can automate some server maintenance tasks through Jenkins jobs.
# following example assumes user 'devops' is running applications on # various deployment machine environments, and wants to give the jenkins # user SSH access to each machine in the environment # log in to the machine running jenkins and become root devops@jenkins ~$ sudo su # as root user, become jenkins user root@jenkins /home/devops# su -s /bin/bash jenkins # use 'ssh-keygen' and follow the prompts to set up a default rsa key on # the jenkins machine jenkins@jenkins:~$ ssh-keygen # use ssh-copy-d to copy public keys from jenkins to various environment machines: ssh-copy-id -i ~/.ssh/id_rsa.pub email@example.com ssh-copy-id -i ~/.ssh/id_rsa.pub firstname.lastname@example.org ssh-copy-id -i ~/.ssh/id_rsa.pub email@example.com # thats it, test the ssh connection from jenkins to each environment's machine: jenkins@jenkins:~$ ssh firstname.lastname@example.org # and so on...
This set up doesn't require any further credentials to be set up in Jenkins.