1

I am trying to deploy code from GitLab to the EC2 instance. However, I am getting the following errors when I run the pipeline

/home/gitlab-runner/.ssh/config: line 1: Bad configuration option: \342\200\234host
/home/gitlab-runner/.ssh/config: terminating, 1 bad configuration options

Here is my .gitlab-ci.yml file that I am using.

stages:
   - QAenv
   - Prod
Deploy to Staging:
  stage: QAenv
  tags:
    - QA
  before_script:
    # Generates to connect to the AWS unit the SSH key.
    - mkdir -p ~/.ssh
    - echo -e “$SSH_PRIVATE_KEY” > ~/.ssh/id_rsa
    # Sets the permission to 600 to prevent a problem with AWS
    # that it’s too unprotected.
    - chmod 600 ~/.ssh/id_rsa
    - 'echo -e “Host *\n\tStrictHostKeyChecking no\n\n” > ~/.ssh/config'
  script:     
    - bash ./gitlab-deploy/.gitlab-deploy.staging.sh   
  environment:     
    name: QAenv     
    # Exposes a button that when clicked take you to the defined URL:
    url: https://your.url.com   

Below is my .gitlab-deploy.staging.sh file that I have set up to deploy to my server.

# !/bin/bash
# Get servers list:
set — f
# Variables from GitLab server:
# Note: They can’t have spaces!!
string=$DEPLOY_SERVER
array=(${string//,/ })
for i in "${!array[@]}"; do
  echo "Deploy project on server ${array[i]}"
  ssh ubuntu@${array[i]} "cd /opt/bau && git pull origin master"
done

I checked my .ssh/config file contents and below is what I can see.

ubuntu@:/home/gitlab-runner/.ssh$ cat config 
“Host *ntStrictHostKeyChecking nonn”

Any ideas about what I am doing wrong and what changes I should make?

Bilal Yousaf
  • 192
  • 2
  • 12

1 Answers1

3

The problem is with.

ubuntu@ip-172-31-42-114:/home/gitlab-runner/.ssh$ cat config 
“Host *ntStrictHostKeyChecking nonn”

Because there are some Unicode characters here, which usually comes when we copy paste code from a document or a webpage.

In your case this char specifically you can see in the output as well.

replace that with " and check for others in your config and update should work.

There are more details in this question getting errors stray ‘\342’ and ‘\200’ and ‘\214’

samtoddler
  • 6,742
  • 2
  • 19
  • 18
  • The canonical is *[Compilation error: stray ‘\302’ in program, etc.](https://stackoverflow.com/questions/19198332)* (though it is in dire need of one or more *really* comprehensive answer) – Peter Mortensen May 08 '22 at 13:27