Q:

How to fix Permission denied (publickey,password) in gitlab Ci/CD?

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.

A:

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 

