Jnnngs
Home
About
 Admin
  4 minutes

Jenkins Deployment ssh-keygen

So, as part of my home lab and the automatic deployment of this blog, Jenkins needs to SSH onto the deployment Raspberry Pi to execute a bash script. Jenkins has been installed using its own username and as it is a service account, the method to generate and copy the ssh-gen keys is different to the standard way for normal linux/ubuntu user accounts.

#Jekins is a service account, so it needs its ssh keys for remote execution to be created differently...

#login to jenkins server and switch to jenkins service user account
sudo su -s /bin/bash jenkins

#create keys. default location will be /var/lib/jenkins/.ssh/id_rsa
ssh-keygen

#copy keys over to destination server
cat /var/lib/jenkins/.ssh/id_rsa.pub | ssh ubuntu@DEPLOYMENT_IP_ADDRESS "mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod -R go= ~/.ssh && cat >> ~/.ssh/authorized_keys"