1

I have below simple script in .gitlab-cl.yml file:

build_deploy_stage:
  stage: build
  environment: Staging
  only:
    - master
  script:

    - mkdir -p ~/.ssh

    - echo "$PRIVATE_KEY" >> ~/.ssh/id_dsa
    - cat ~/.ssh/id_dsa
    - chmod 600 ~/.ssh/id_dsa
    - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
    - cat ~/.ssh/config
    - scp   myfile.js user@example.com:~

But I get this error when job is run, executing the last line (scp command):

Warning: Permanently added 'example.com' (ECDSA) to the list of known hosts.
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).

I spent whole day but could not fix it. I verified that $PRIVATE_KEY exists. I generated key pair while logged into example.com copying the generated private to PRIVATE_KEY variable on gitlab. How to fix this problem?

Note that it is dsa key.

ace
  • 11,526
  • 39
  • 113
  • 193
  • Try running `ssh -vvv user@example.com` and [edit] your question to include the verbose output which ssh produces. – Kenster Sep 09 '18 at 20:08

1 Answers1

2

Check your permission for ~/.ssh (700) and all the files in them (600)

Your config file, for instance, might have default permissions that are too large. If you can, activate a debug session in the sshd of the remote server: you will see if an dsa key is accepted (for recent version of sshd, that might be restricted). rsa would be better.
As seen here, OpenSSH 7.0 and higher no longer accept DSA keys by default.

The OP ace confirms in the comments:

I fixed the problem when I regenerated tsa key pairs instead of dsa keys

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250