Search code examples
dockersecuritysshazure-pipelinesssh-keys

How to scp something with public key in azure-pipelines?


My azure pipeline contains compiling of a project and building docker image from it.

Now I want to copy this image to target machine and run it there.

With shell script what I was doing is:

sudo docker build -f src/main/docker/Dockerfile.jvm -t $docker_name .
sudo docker save $docker_name > $tar_name

scp $tar_name $target_path

I think I did build and save parts in azure-pipelines already.

But how to do scp? I need some ssh key in pipeline to authorize it on target machine. It's can't be my key pair since it will be compromised. How to make one for pipeline then?


Here is the task description. It states, that

The task supports use of an SSH key pair to connect to the remote machine(s).

But doesn't explain, how to use key pair if I have it.


Solution

  • I found Azure has special pipeline task called CopyFilesOverSSH. It receives key in the form of pre-configured "Service connection", which should be configured on seprate page:

    enter image description here

    Configuring service connection involves storing keys correctly.

    There is no need to call scp command itself.