How to generate and store read/write SSH keys

One may sometimes want to interact with a GitHub or Bitbucket repository from within a CircleCI job, either in more than a read-only capacity, or with a repository external to the one being used for the current job. Either option requires generating a new SSH key, storing the public portion in the GitHub or Bitbucket repository with which the project will be interacting, and storing the private portion in CircleCI.

With the release of macOS Mojave, the default SSH key generated by ssh-keygen is no longer the correct format for CircleCI. To generate a correctly formatted key on a computer running macOS, run the following command:

ssh-keygen -t rsa -b 4096 -m PEM

See GitHub and Bitbucket documentation for guidelines on storing SSH public keys:

To store the private key in CircleCI, visit the Project Settings/SSH Permissions page:

https://circleci.com/[YOUR_VCS]/[YOUR_ORG]/[YOUR_PROJECT]/edit#ssh

Make sure to specify the hostname (github.com or bitbucket.org) when adding the private key.

Finally, the key will need to be added to your config.yml file:

https://circleci.com/docs/2.0/configuration-reference/#add_ssh_keys

Was this article helpful?
3 out of 6 found this helpful

Comments

0 comments

Please sign in to leave a comment.