-1

I am trying to push a file to GH repo from pipeline and failing at ssh-add $private_key / ssh-add <(cat git-private-key | base64 --decode)

git config --global user.name "CI Bot"
git config --global user.email "localhost"
eval $(ssh-agent -s)
echo -e $private_key | base64 -w0 > git-private-key
ssh-add <(cat git-private-key | base64 --decode)

enter image description here

I tried other solutions and things like eval ssh-agent, update libcrypto, chmod 600 file permission, and passing key in plane and base64 format, but I am getting the same error.

Pls find the below ss trying multiple ways enter image description here

asked Feb 16, 2024 at 11:40
2
  • Curious, but why are you base64-encoding the key in the first place? You already have the content available in the $private_key envvar, just put it in a temporary file, ssh-add that, and go. (Also: please don't screenshot text if you can copy and paste.) Commented Feb 16, 2024 at 17:25
  • @JimRedmond So there are couple of ways I tried to pass the key to ssh-add as mentioned plane and base64 but both did not solve it. The reason using base64 is got a solution from someone which is a fix for him so tried. For the screenshot I tried to put as much text but picture at some point gives more visibility I'll keep this in mind going forward. - Thanks Commented Feb 19, 2024 at 6:35

3 Answers 3

1

I know it's an old question, but it took me quite some time to figure it out, so it might help the one or another.

For me the problem was that I was trying to set-up deployment on staging but I have not yet protected the staging branch the deployment ran on. But the variable with the private key was protected by default, which means, that it won't be exposed to non-protected branches.

So the solution would be to protect your branch to make the ssh key working. Or (not recommended) unprotect your variable.

answered May 29, 2024 at 13:03
Sign up to request clarification or add additional context in comments.

Comments

0

After some debugging I have it fixed by correcting the way it is being referenced in ssh-add.

I have used sed to update the $private_key before ssh-add

echo -e $private_key | sed 's/--- /---\n/g;s/ ----/\n----/g' | sed '2s/ /\n/g' > git-private-key

This makes sure that private_key will have a correct format earlier

----beginkey---- KEY SECRET DATA IN MULTIPLE LINES ----endkey----

After sed command

----beginkey----
KEY SECRET DATA
----endkey----
answered Feb 19, 2024 at 12:03

Comments

0

I faced this error because I had made the private_key variable protected in gitlab. So, on removing the protected tick allowed me to continue

answered May 23, 2024 at 5:04

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.