Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup multiple ssh identities for single hg repository?

I am using ssh publickey authentication for my mercurial repository. So I have:

[ui]
ssh = ssh -i ~/.ssh/id_rsa -C 

in my .hgrc. This works fine and allows me to push/pull to an ssh-authenticated repo. However, I want to be able to push/pull to another repo that requires a different identity. How can I configure my .hgrc file so the identity is tied to a particular path. I guess I'd want something like:

[ui]
one.prefix = someserver.com
one.ssh = ssh -i ~/.ssh/id_rsa -C
two.prefix = otherserver.com
two.ssh = ssh -i ~/.ssh/otherid_rsa -C
like image 911
noone Avatar asked Jan 28 '11 21:01

noone


People also ask

Can I have multiple SSH keys on one device?

You use SSH for connecting to remote servers, which also includes managing your code using Git and syncing with remote repositories. Even though it is considered a good practice to have one private-public key pair per device, sometimes you need to use multiple keys and/or you have unorthodox key names.

Can you have multiple SSH keys for GitHub?

For instance, you can run an Organization's GitHub account and another one for your personal projects all on the same computer. In this article, you will learn how to use multiple SSH keys for different GitHub accounts. While working with two different GitHub accounts, you must set them up using an SSH key.


1 Answers

In your ~/.ssh/config, add

Host someserver.com
IdentityFile ~/.ssh/id_rsa

Host otherserver.com
IdentityFile ~/.ssh/otherid_rsa

and anybody (including hg and interactive use) using ssh to connect to hosts someserver.com or otherserver.com will use the specified identity files.

See ssh_config for other options.

like image 81
ephemient Avatar answered Nov 14 '22 15:11

ephemient