Search code examples
linuxjenkinsamazon-ec2centos

Copying Jenkins jobs folder from server to EC2 Instances


We will be migrating Jenkins from old server to EC2 Instances server. We wish to copy few of the Jenkins job from old server to EC2. Been trying out to copy using SCP command.

scp -r FOLDER1/ ec2-user@ec2-<I.P>.ap-southeast-1.compute.amazonaws.com:/var/lib/jenkins/jobs/

Above command entered when I am logged into old server and in /var/lib/jenkins/jobs/ directory.

I am getting below message:

Permission denied (publickey,gssapi-keyex,gssapi-with-mic). lost connection

Does anyone tried before to copy Jenkins jobs folder from old server to EC2 server? Does .pem need to be in the same directory of old server /var/lib/jenkins/jobs?


Solution

  • You will need to refer the key using switch of -i as in the example below:

    scp -i "aws_keypair.pem" -r FOLDER1/* ec2-user@ec2-<I.P>.ap-southeast-1.compute.amazonaws.com:/var/lib/jenkins/jobs/
    

    The pem file could be in any directory, just make sure that the path is included after the -i

    Also to mention to set the key permissions restrictive lets say 400 using command chmod 400 <key file>