Setting Up an SSH Key for CircleCI and GitLab and GitHub App Integration on Windows

Overview

Currently, the way the Windows Environment utilizes the built-in checkout step, it will fail with the following error.

Warning: checkout key has zero length
Writing SSH key for checkout to "C:\\Users\\circleci\\.ssh\\id_rsa"
Cloning git repository
Cloning into '.'...
Load key "C:/Users/circleci/.ssh/id_rsa": error in libcrypto
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

 

Solution 

Step 1: Delete the Pre-configured Checkout Key (Optional)

To avoid confusion, you can delete the pre-configured checkout key on CircleCI and your VCS.

On CircleCI, navigate to the project settings for your project, switch to the "SSH Keys" tab, and delete the key listed in the section titled "Additional SSH Keys".

 

On GitLab, go to the "Settings" menu of the project, switch to the "Repository" tab, expand "Deploy keys", and delete the one titled "circleci-pipeline-triggers".

On GitHub App, go to the "Settings" menu of the project, switch to the "Deploy Keys" tab, and delete the one titled "GitHub App Trigger".

 

Step 2: Generate a New Keypair for SSH

Run the following command on your computer to generate a new keypair:

KEYNAME=<your_key_name>.pem
ssh-keygen -t ed25519 -f $KEYNAME -N ""

 

Step 3: Register the Generated Keypair

On CircleCI, go to project settings, switch to the "SSH Keys" tab, click "Add SSH Key", and paste the content of $KEYNAME into the "Private Key" field.

 

On GitLab, go to the "Settings" menu of the project, switch to the "Repository" tab, expand "Deploy keys", set a title (e.g., circleci-checkout-key), paste the content of $KEYNAME.pem.pub into the "Key" field, and click "Add key".

On GitHub App, go to the "Settings" menu of the project, switch to the "Deploy Keys" section, set a title (e.g., circleci-checkout-key), paste the content of $KEYNAME.pem.pub into the "Key" field, and click "Add key".

 

Step 4: Update your config.yml

You can retrieve the Fingerprint from the "SSH Key" section in your Project Settings. 

This is the same place we added the key in Step 3.

Add the following stanza just before the checkout step in your config.yml (replace THE_FINGER_PRINT_YOU_GOT_IN_THE_PREVIOUS_STEP accordingly):

- add_ssh_keys:
    fingerprints:
      - "THE_FINGER_PRINT_YOU_GOT_IN_THE_PREVIOUS_STEP"

Commit and Push your changes. Now, your Windows build should be able to check out your code without errors.

 

Additional Resources

 

Was this article helpful?
2 out of 4 found this helpful

Comments

0 comments

Article is closed for comments.