-1

im learning jenkins for the moment and i had a problem with sshagent . i can't connect to my remote machine . first i'm trying to deploy into kubernetes using jenkins .and i'm using ssh agent to get into kubernetes-master so i can run command from it . so the probleme is i genareted a ssh key in my kubernetes-master and i added the private key to jenkins but it not working . any help here plz here you find the stage .of deployment in the pipeline
and the output console when i executed the job jenkins output console

 stage('deploy to K8s cluster '){
        steps{
             sshagent(['Jenkins-Access-Kube']) {
                         sh"scp -r -o StrictHostKeyChecking=no  /home/automate-deployment-on-k8s/complete-demo.yaml younes@192.168.8.199:/home/younes/k8s"
                script{
                  try{
                        sh 'ssh younes@192.168.8.199  kubectl apply -f . '
                  }catch(error){
                        sh 'ssh younes@192.168.8.199 kubectl create -f . '
                  }
                }

                }

1 Answers1

0

Setting 700 to .ssh and 600 to authorized_keys solved the issue.

chmod 700 /root/.ssh
chmod 600 /root/.ssh/authorized_keys
Abhishek Patwa
  • 167
  • 2
  • 5
  • 1
    wondering, how do you know it solv**ed**the issue? :) – P.... Jun 09 '22 at 15:40
  • your Jenkins output shows a permission denied error, which is related to file permission. just try to update the permission. and check again. – Abhishek Patwa Jun 09 '22 at 15:42
  • I think the OP is trying to `scp` through the user `younes`. In the `scp` command he has not used `-i ` that caused the `permission denied`. Based on the logs, the private keys are copied to `/var/lib/jenkins` but he did not provide it `scp`. – P.... Jun 09 '22 at 15:55
  • Also, the error for permissions(`group/world readable`) would generate different errors(feel free to reproduce in your machine). Not the error shown In the logs. So, **perhaps the answer is not correct.** . (happy to be corrected) – P.... Jun 09 '22 at 15:57