title: Storing SSH Private Key in GitLab repository variables
body: <p>Using GitLab CI, I want to push production code to a remote webhost.</p>
  <p>To connect with SSH, I am storing the key pair's private key in the variables of my GitLab repository. I've also copied the public key to the authorized keys of the server. This is (part of) my <code>.gitlab-ci.yml</code>.</p>
  <pre><code>image: ubuntu
  
  before_script:
    # Setup SSH credentials and known host
    - which ssh-agent || ( apt-get update -y &amp;&amp; apt-get install openssh-client -y )
    - mkdir -p ~/.ssh
    - echo &quot;$SSH_PRIVATE&quot; | tr -d '\r' &gt; ~/.ssh/id_rsa
    - chmod 700 ~/.ssh/id_rsa
    - eval &quot;$(ssh-agent -s)&quot;
    - ssh-add ~/.ssh/id_rsa
    - echo &quot;$SSH_KNOWN_HOSTS&quot;
    - echo &quot;$SSH_KNOWN_HOSTS&quot; &gt; ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
  </code></pre>
  <p>This method works, but I'm questioning the security of it. Is my private key safe this way? How else can I achieve the result that I'm looking for?</p>
  <p>EDIT: I'm particularly questioning the security of this method in a production environment.</p>