2

My problem is similar to this one,

Error loading key "/tmp/.ssh/gitlab": invalid format

But I have tried all the ways and I can't get it to work. I have the SSH_PRIVATE_KEY variable set, because if I do echo in the same before_script I can see it. I have tried with a line break at the end of SSH_PRIVATE_KEY but it doesn't work.

From my local machine i can do this without problem:

export SSH_PRIVATE_KEY="-----BEGIN OPENSSH PRIVATE KEY-----
thecharsinthekey=
-----END OPENSSH PRIVATE KEY-----"
echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
Identity added: (stdin) (GitLab SSH)

My config:

image: trion/ng-cli-karma:12.2.12

cache:
  paths:
    - node_modules/

before_script:
  - which ssh-agent || ( apt-get update -y && apt-get install openssh-client git -y )
  - mkdir -p ~/.ssh
  - echo $SSH_PRIVATE_KEY | tr -d '\r' > ~/.ssh/gitlab
  - chmod 700 ~/.ssh/gitlab
  - eval $(ssh-agent -s)
  - ssh-add ~/.ssh/gitlab
  - ssh-keyscan $VM_IPADDRESS >> ~/.ssh/known_hosts
  - chmod 644 ~/.ssh/known_hosts

deploy_qa:
  stage: deploy
  environment: Staging
  only:
    - master
  script:
    - rm ./package-lock.json
    - cd /my/app/dir
    - ls
    - scp -o stricthostkeychecking=no -r . $SSH_USER@$VM_IPADDRESS:/home/user/my/app/dir
Conde
  • 785
  • 15
  • 31
  • 3
    The working version is `echo "$SSH_PRIVATE_KEY"` and broken version is `echo $SSH_PRIVATE_KEY`. These are different and not the same, and the latter not the same as the Q you link to. PS: since you set `stricthostkeychecking=no` on `scp` you don't actually need the `ssh-keyscan >known_hosts` at all. – dave_thompson_085 Jan 30 '22 at 23:15
  • @dave_thompson_085 Yes, you are right, thank you very much! – Conde Jan 31 '22 at 17:49

0 Answers0