How to setup multiple id_rsa.pub on my centos server?

2

I have this legacy server with CentOS release 6.6 (Final), w/ git version git version 1.7.1

I need to pull on it different Github projects. Access to server is shared by multiple persons via a common auth system.

Taken into account that the above env cannot be changed or upgraded.

I have the following issue. I have already connected successfully to a git repo and deal with it by defining a Deploykey, the unique I have actually defined in:

  /home/dev-user/.ssh/id_rsa.pub

Now I've tried to add the same deploy key to manage a different github repo. But github 's giving me an error , key is already in use.

So I'm thinking to create multiple id_rsa_reponame.pub ssh keys to pull (mainly) my github repo to this server.

Can this be considered a best practice in this case? Id yes...How can I create different named public keys to use as deploy key on github repo?

Any other way to solve this is welcome.

Thanks

UPDATE

I've tested the following from another development machine. In this machine I already had a

 /home/username/id_rsa.pub

Already defined as deploy key on a github repo and working correctly.

Then I issued the command:

ssh-keygen -t rsa -b 4096 -C "myname@mymachine.local"

When prompted I gave a different name to the key like:

 /home/username/id_rsa_mytest.pub

Then I copied the content of this file and set as deploy key for another repo.

I tried to git clone:

  git clone git@github.com:githubAccount/myrepo.it

But got:

fatal: Could not read from remote repository.

Please make sure you have the correct access rights

I believe that local machine is not trying automatically all my pub keys to connect to github via ssh.

How can I achieve that?

koalaok

Posted 2019-05-08T11:20:10.110

Reputation: 191

Add the key in your personal settings (the menu with your profile picture in the upper right), not in the repository settings. If it is in your personal settings you can use it for all your repositories – Gerald Schneider – 2019-05-08T11:27:14.227

@GeraldSchneider I think this isnt Ideal since any developer accessing to the legacy server via dev-user will be able to pull push via my github account. Is it? – koalaok – 2019-05-08T11:34:06.690

True. Then you will need different deploy keys. But I don't understand what you are asking in this case ... the first thing ssh-keygen asks you when you start it is the filename where it should store the key. – Gerald Schneider – 2019-05-08T11:41:04.497

Ok. But I'm not sure If having multiple id_rsa_name.pub in my server .ssh dir might affect some previous configuration based on the default id_rsa.pub All the public key defined there will be active and equally available? Is the some circumstance that creating a new .pub file might create some issue? – koalaok – 2019-05-08T12:51:14.167

Answers

1

I have found the solution for what I was looking for; thanks to this resource:

https://medium.com/@dustinfarris/managing-multiple-github-deploy-keys-on-a-single-server-f81f8f23e473

One point which is not so straightforward/clear in the post. The line:

 Host github-repo2

In config file

  ~/.ssh/config

is like a custom name to be used subsequently when issuing the command :

 git clone github-repo2:yourgithubuser/repo2

Actually the “Host” term is not so friendly to make you understand his function in the configuration.(It is a reference as username @ hostname using the specific identity file)

koalaok

Posted 2019-05-08T11:20:10.110

Reputation: 191