Ssh keys with alpine docker

I’m trying to copy files over to a remote host using scp and ssh keys with alpine docker, but I’m having issues reading in my key.

I’m following the guide here:

Just calling

ssh-add <(echo "$SSH_PRIVATE_KEY")

won’t work as sh seems not to understand the syntax and thinks there are too many brackets. Installing bash and running

bash -c 'ssh-add <(echo "$SSH_PRIVATE_KEY")'

gets passed that issue, but I’m getting Error loading key "/dev/fd/63": invalid format.

What should be in $SSH_PRIVATE_KEY? I just copied in my ssh private key into a pipeline variable (without the -----BEGIN RSA PRIVATE KEY----- and -----END RSA PRIVATE KEY----- parts)

Have you tried to pass the key with -----BEGIN RSA PRIVATE KEY----- and -----END RSA PRIVATE KEY----- parts ? I’d expect ssh commands to expect the complete keyfile.

Thanks bartj, that fixed the key import issue. I’m still not able to send files over though using scp, as my connection times out. Copying the same commands in an interactive alphine docker do work though.

- apk add --update openssh-client bash
- eval $(ssh-agent -s)
- bash -c 'ssh-add <(echo "$SSH_PRIVATE_KEY")'
- scp -o StrictHostKeyChecking=no -r site_files/*

Well, if trying “telnet 22” gives you a reply, that should exclude firewall problems. Otherwise try scp with the -v option to debug. Also, if username is root, this might not work as that user is mostly blocked by default for ssh servers. Last option is to manually add the private key in the command via the -i option, just see whether it indeed makes a difference.