Multiple git accounts in one computer (ssh)
Pau Garcia
Posted on April 2, 2023
First we need to create the ssh keys for each account
ssh-keygen -t rsa -C "your@email.com"
cd .ssh
code .
// copy ssh ky from id_rsa.pub and paste it in a new ssh key in github
if error chech https://stackoverflow.com/questions/18683092/how-to-run-ssh-add-on-windows
ssh-add /ssh/id_rsa
if its not working:
ssh-agent -s
`
repeat this steps with the other account
Then create a config file, that should look loke this:
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_Account1
Host github2.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_Account2
Match Host github.com exec "git config --get user.name | grep 'name_Account_1' > /dev/null"
IdentityFile ~/.ssh/id_rsa_Account1
Match Host github.com exec "git config --get user.name | grep 'name_Account_2' > /dev/null"
IdentityFile ~/.ssh/id_rsa_Account2
Then create 2 folders where you will create and work with your git projects
The .gitconfig file should look like this
`shell
[user]
email = Account1@gmail.com
name = Account1
[core]
editor = nvim
[includeif "gitdir:/media/pau/564548676397F900/main/"]
path = ./path/to/Account1/folder/.gitconfig
[includeif "gitdir:/media/pau/564548676397F900/UPC/"]
path = /path/to/Account2/folder/.gitconfig
[credential "https://github.com"]
helper =
helper = !/usr/bin/gh auth git-credential
[credential "https://gist.github.com"]
helper =
helper = !/usr/bin/gh auth git-credential
`
Then, in each Account folder, create a .gitconfig, that should look like this:
`shell
[user]
email = Account1@mail.com
name = Account1
signingkey = DEADBEEF
[core]
sshCommand = "ssh -i ~/.ssh/id_rsa_Account1"
`
make the same for the other folder, and you should have configured well you double git account using ssh
I've made all this using git cmd
some usefull references
https://www.youtube.com/watch?v=2MGGJtTH0bQ
https://gist.github.com/rahularity/86da20fe3858e6b311de068201d279e3
Posted on April 2, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 30, 2024