1. The same computer can have 2 git accounts (different websites)
First of all, different websites can of course use the same mailbox. For example, my github, gitlab, and bitbucket accounts are all gotodiscuss[at]gmail.com. At this time, there is no need to worry about the key problem, because the uniqueness of the push pull authentication of these websites is For example, I have 2 accounts on my windows, one gitlab and one github (all use id_rsa)
host github hostname github.com Port 22 host gitlab.ikeepstudying.com hostname gitlab.ikeepstudying.com Port 65095
The location of the key does not need to be specified. Because id_rsa is read by default
In this way, there is no difference in using it, and the remote can be operated the same as usual. Because the mailbox is the same.
2. There are 2 github accounts on the same computer? what to do
For example, 2 users simulated on my server
#[email protected] my first account in gitlab gotodiscuss host gitlab.gotodiscuss.com hostname gitlab.gotodiscuss.com Port 65095 User gotodiscuss IdentityFile /home/suzie/.ssh/id_rsa # My second account test in gitlab host gitlab-test.gotodiscuss.com hostname gitlab.gotodiscuss.com Port 65095 User test IdentityFile /home/suzie/.ssh/id_rsa_second #[email protected] My account on github host github-osteach.com hostname github.com Port 22 User osteach IdentityFile /home/suzie/.ssh/id_rsa_second
Therefore, the basic writing of config:
Host myhost (here is the abbreviation of the custom host, you can use the command ssh myhost to connect to the remote server in the future) [note the indentation below]
User login user name (eg: git)
HostName host name can be ip or domain name (eg: github.com or bitbucket.org)
Port server open-ssh port (default: 22, generally do not write this line by default)
IdentityFile certificate file path (such as ~/.ssh/id_rsa_*)
In this case, a few points need to be paid attention to
1. There is a problem with remote pull push, because we need to set the mailbox problem. When we pull, we recognize the mailbox, 2 github accounts, and 2 mailboxes. Naturally, we can't use the global user.email.
git config -e [--global] # Edit Git configuration file git config --global user.name yanhaijing git config --global user.email [email protected] git config --list #View configuration information git help config #Get help information #1. Cancel global git config --global --unset user.name git config --global --unset user.email #2. Set each project repo's own user.email git config user.email "[email protected]" git config user.name "suzie"
After that, there is no problem with push pull.
Remark
generate ssh key
ssh-keygen -t rsa -C "your mail" ( current directory ) Then you can name the default id_rsa or id_rsa_second to put the corresponding pub on the public server.
The ssh-keygen command needs to be run in the project directory, and it needs to cancel the global user.name and user.email, and create a local user.name and user.email (the same as your git account). This harmed me and wasted a lot of time.
ps.
If sourcetree uses multiple accounts, remember to modify the config file, and select the private key in "add ssh key" in the "Tools" menu. The most important thing is to use the modified path when cloning.
1.//When git clone the project, it prompts Host key verification failed
When using the ssh protocol, the key of the opposite server will be verified. ssh cannot confirm that the key presented by the server is authentic, so it asks you if the key is really from the server you want to connect to. You didn't say "yes" so ssh thinks you don't want to continue the connection, and of course the connection fails
2.//git clone Permissions 0644 for ‘~/.ssh/id_rsa’ are too open
Just drop the permissions to 0600.
3.//Bad owner or permissions on /home/xxx/.ssh/config
ssh config file permissions problem, reduce the permissions to 0600.
Others: Add SSH public keys to multiple GitHub accounts
Transferred from: SSH key switching for multiple git accounts