GitHub multiple accounts setup
My two GitHub accounts are the main one (working on open source projects and my own code) and the secondary one (updating the Hexo blog).
This article shows you how to configure SSH files for multiple GitHub accounts to work properly without conflicts.
SSH is generated
Because different GitHub servers cannot use the same SSH public key, you need to generate two different SSHS corresponding to two primary and secondary accounts.
Ubuntu generates SSH using the following commands:
ssh-keygen -t rsa -f ~/.ssh/id_rsa_blog -C "[email protected]"
ssh-keygen -t rsa -f ~/.ssh/id_rsa -C "[email protected]"
Copy the code
The -f option specifies the file name to generate the key pair.
The.ssh/ directory should look like this:
SSH configuration
Run the ~/. SSH /config SSH configuration file to create an SSH configuration file.
# [email protected] Host github-main.com HostName github.com User git IdentityFile ~/.ssh/id_rsa # [email protected] Host github-blog.com HostName github.com User git IdentityFile ~/.ssh/id_rsa_blogCopy the code
Then, to add a remote repository using the main account in the future, add:
git remote add origin [email protected]:username/demo.git
Copy the code
Similarly, using a blog account looks like this:
git remote add origin [email protected]:username/demo.git
Copy the code
Instead of the original:
git remote add origin [email protected]:username/demo.git
Copy the code
Test whether the configuration is successful
After deploying the appropriate SSH public key to GitHub, try testing a few files in the appropriate local repository git push.