How to Use a Custom SSH Identity with Git

By Andre Perunicic | August 24, 2017

This page describes how to specify which SSH profile to use with git. This can be handy if you have more than one GitHub account and don’t wish to reuse your default SSH key or type in a password every time you push or pull. The commands will be written from the perspective of a GitHub user, but should be easy to adapt to other scenarios as well.

Step-by-Step Instructions

  1. Generate a new SSH key:
ssh-keygen -t rsa -b 4096 -C "name@domain.com"

Let’s assume the identity file you created is in ~/.ssh/id_rsa_custom.

  1. Upload the key to GitHub (link leads to GitHub’s instructions).

  2. SSH will look for profiles in the user’s ~/.ssh/config file. Add something similar to this to that file:

Host custom
      Hostname        github.com
      IdentityFile    ~/.ssh/id_rsa_custom
      IdentitiesOnly yes

The IdentitiesOnly yes option is required to prevent the SSH sending the identity file matching the default filename, as is the default. If you have a file named ~/.ssh/id_rsa that will get tried BEFORE your ~/.ssh/id_rsa_custom without this option.

  1. Associate the remote git repository to your local repo:
git remote add origin git@custom:user/myrepo.git

If starting from scratch, you can just do:

git clone git@custom:user/myrepo.git

From then on, commands like git push -v origin master should work normally without any prompts.

If you got to this page from Google, I hope you found the answer you were looking for. Get in touch with us if you have a data sourcing or analysis task you want done quickly and reliably.

Suggested Articles

If you enjoyed this article, then you might also enjoy these related ones.

Breaking Out of the Chrome/WebExtension Sandbox

By Evan Sangaline
on September 14, 2018

A short guide to breaking out of the WebExtension content script sandbox.

Read more

Building a YouTube MP3 Downloader with Exodus, FFmpeg, and AWS Lambda

By Evan Sangaline
on May 21, 2018

A short guide to building a practical YouTube MP3 downloader bookmarklet using Amazon Lambda.

Read more

Running FFmpeg on AWS Lambda for 1.9% the cost of AWS Elastic Transcoder

By Evan Sangaline
on May 2, 2018

A guide to building a transcoder using Exodus, FFmpeg, and AWS Lambda.

Read more

Comments