How to use two GitHub accounts on the same computer
Scenario: when using github, you all know that you need to add an SSH key to the account for access. refer to the specific settings. Of course, if you use one account on multiple machines, you can add multiple SSH keys to the account. Because github uses fingerprint of the SSH key to determine which account you are using, rather than the user name, you can directly execute the following statement locally after setting, it will automatically use your. log on to the account corresponding to ssh/id_rsa.pub, and then execute related commands.
1 # local database 2 $ git init3 $ git commit-am "first commit '4 5 # push to github 6 $ git remote add origin git@github.com: xxxx/test. git7 $ git push origin master
However, if you want to use two github accounts (such as private accounts and work accounts) on a machine ). In this case, how do I specify the account's test warehouse for pushing?
Solution (assuming that you already have a private account and are OK, you want to use another working account ):
1: generate an SSH Key for the work account
$ Ssh-keygen-t rsa-C "your-email-address" # Do not overwrite the existing id_rsa when storing the key. Use a new name, such as id_rsa_work.
2: Add id_rsa_work.pub to your work account.
3: add the key to the ssh agent. Because the default. ssh/id_rsa is not used, you need to display the location of your new key to the ssh agent.
$ Ssh-add ~ /. Ssh/id_rsa_work # You can use ssh-add-l to confirm the result.
4: Configure. ssh/config
$ Vi. ssh/config # Add the following content # default githubHost github.com HostName github.com IdentityFile ~ /. Ssh/id_rsaHost github_work HostName github.com IdentityFile ~ /. Ssh/id_rsa_work
5: In this case, you can use the github.com alias github_work to make it clear that if you use the id_rsa_work SSH key to connect to github, you can use the work account for operations.
# Local database creation $ git init $ git commit-am "first commit '# push to github $ git remote add origin git @ github_work: xxxx/test. git $ git push origin master
GitHub Tutorials:
Create a personal technical blog via GitHub
GitHub tutorials
Git tag management details
Git branch management
Git remote repository details
Git local Repository (Repository) Details
Git server setup and Client installation
Git Overview
Share practical GitHub tutorials
GitHub details: click here
GitHub: click here
This article permanently updates the link address: