dracoblue.net

Custom identity file (id_rsa.pub) with git client

Whenever you want to use a custom identity file with ssh, you usually use the -i parameter.

$ ssh -i ~/.ssh/other_id_rsa [email protected]

This will validate against ~/.ssh/otheridrsa.pub and not the default one at ~/.ssh/id_rsa.pub.

If you want to use this with the default git client, it won't work. You cannot specify the identity file when cloning/pulling from or pushing to a repository, yet.

So:

$ git remote add origin ssh://[email protected]:repository.git
$ git pull origin master

will fail, because it's using the default rsa key at ~/.ssh/id_rsa.

Instead you can use this workaround.

Adjust your ~/.ssh/config and add:

Host example
  Hostname example.com
  User myuser
  IdentityFile ~/.ssh/other_id_rsa

Now use the ssh host alias as your repository:

$ git remote add origin example:repository.git
$ pull origin master

And it should use the otheridrsa-key!

In linux, ssh by
@ 20 Mar 2011, Comments at Reddit & Hackernews

Give something back

Were my blog posts useful to you? If you want to give back, support one of these charities, too!

Report hate in social media Campact e.V. With our technology and your help, we protect the oceans from plastic waste. Gesellschaft fur Freiheitsrechte e. V. The civil eye in the mediterranean

Recent Dev-Articles

Read recently

Recent Files

About