Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git SSH Key : Two different account for github and gitlab [duplicate]

Is there any way to operate GitLab and GitHub accounts through SSH Key by using two different email address?

I Have two mail id, [email protected] and [email protected] and I want to push some projects to gitlab as well as some other projects to github and also I want to avoid password entering prompt in every push command. Is it possible?

like image 828
JPG Avatar asked Aug 05 '17 08:08

JPG


1 Answers

You could try working with ssh instead of https: upload your public ssh git to the server, and use an ssh url. For instance, for github you shouldn't have a url like

https://github.com/<username>/<repo>.git

but you should have

[email protected]:<username>/<repo>.git

--

Now, to use different ssh keys or username, you could try setting your ~/.ssh/config file to something like

Host           gitlab.com
HostName       gitlab.com
IdentityFile   ~/.ssh/gitlab
User           [email protected]

Host           github.com
HostName       github.com
IdentityFile   ~/.ssh/github
User           [email protected]

WhereIdentityFile are the path to your private ssh keys

like image 137
gturri Avatar answered Sep 19 '22 22:09

gturri