Scenario
I have two github accounts, one is my personal Github account
personalAccount, one is my job accountworkAccount. When I push code at work asworkAccountto my personal repo.
it’s show - ERROR: Permission to personalAccount/repo denied to workAccount
How do I have the ability to push and pull to multiple accounts via ssh key?
Solution
Generate new SSH keys
ssh-keygen -t rsa -b 4096 -f "$HOME/.ssh/id_rsa_personalAccount"Attach the New SSH Key
Add
id_rsa_personalAccount.pubtopersonalAccountGithub accountAdd Key to the ssh-agent
ssh-add "$HOME/.ssh/id_rsa_personalAccount" # can use ssh-add -l command to check if is successful addedCreate a Config File
vim "$HOME/.ssh/config"content of config file
# company Host github.com IdentityFile ~/.ssh/id_rsa HostName github.com User workAccount # personal Host github.com-personal IdentityFile ~/.ssh/id_rsa_personalAccount HostName github.com User personalAccountChange remote url
git remote set-url origin git@github.com-personal:personalAccount/test.git
Then I can push to my personal repo from company. Wa la la ~~