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
  • 414
  • 6
  • 19
  • 3
    Replace all `“` with `"`. – Cyrus Jan 19 '21 at 18:52
  • 2
    Btw.: Replace `# !` with `#!`. – Cyrus Jan 19 '21 at 18:54
  • 1
    You also need to fix the close quotes. – Gordon Davisson Jan 19 '21 at 18:59
  • 342 (octal) is a signature start of a UTF-8 byte sequence. 342 200 234 (octal) [is the UTF-8 sequence for LEFT DOUBLE QUOTATION MARK (U+201C)](https://stackoverflow.com/questions/19198332/compilation-error-stray-302-in-program-etc#comment117544674_19198332). It can be searched for in a modern text editor with `\x{201C}` in regular expression mode. – Peter Mortensen Feb 21 '23 at 08:04
  • Using [Geany](https://pmortensen.eu/world2/2020/03/29/using-geany/#comment-68), there were two hits in the .yml part of this question. RIGHT DOUBLE QUOTATION MARK (U+201D) would have to be fixed as well. – Peter Mortensen Feb 21 '23 at 08:08

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
  • 8,463
  • 2
  • 26
  • 21
  • 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