Last week I used Git’s GIT_SSH_COMMAND environment variable to force the a command running in a CircleCI job to use one of CircleCI’s “Additional SSH Keys” instead of the “deploy key”.
- Add an “Additional SSH Key” to CircleCI. Take note of its fingerprint.
- Use the special “add_ssh_keys” special step in your CircleCI configuration to add the SSH key to your job. This step will add a file named “id_rsa_FINGERPRINT”.
- Set the GIT_SSH_COMMAND to force git to use your desired key:
environment:
GIT_SSH_COMMAND: "ssh -i /home/circleci/.ssh/id_rsa_FINGERPRINT -o UserKnownHostsFile=/home/circleci/.ssh/known_hosts"