1. Clear the global user name and email address

  • perform
git config --global --unset user.name
git config --global --unset user.email
Copy the code
  • Verify that the deletion was successful
git config --global user.name
git config --global user.email
Copy the code

2. Generate new SSH Keys

  • Execute the command
cd ~/.ssh 
ssh-keygen -t rsa -C "email"
Copy the code
  • Then customize the file nameid_rsa_giteeThe default name isid_rsa
Enter file in which to save the key (~ path /.ssh/id_rsa): id_rsa_giteeCopy the code
  • validationSSH KeysCheck whether the file is generated successfully.
cd ~/.ssh
ls 
cat id_rsa_gitlab.pub
cat id_rsa_gitee.pub
Copy the code

3. Add and identify SSH Keys

  • The default value isid_rsa
ssh-agent bash
ssh-add ~/.ssh/id_rsa_gitee
ssh-add ~/.ssh/id_rsa_gitlab
Copy the code

4. Add the new SSH Keys to the SSH of the Git account

  • copySSH Keys
pbcopy < id_rsa_gitee.pub
pbcopy < id_rsa_gitlab.pub
Copy the code
  • Added to thegiteeorgitlabthessh

5. Create and configure the config file

  • Create the file and open it
SSH /config # open ~/.ssh/config #Copy the code
  • Adding file Contents
// Gitee configuration Host Gitee // site alias HostName gitee.com // Hosting site domain name User <#username#> // Hosting site User name IdentityFile ~/.ssh/id_rsa_gitee // Key file used // Gitlab configuration Host Gitlab // site alias HostName git.nucarf.cn // Host site domain name User <#username#> // Host site username IdentityFile ~/.ssh/id_rsa_gitlab // The key file to useCopy the code

6. Verify your connection to Git

SSH -t [email protected] SSH -t [email protected] // Print successfully // Hi XXX! You've successfully authenticated, but GITEE.COM does not provide shell access. // Welcome to GitLab, @XXXXX!Copy the code

Q&A

Permission denied (Publickey)

  • The public and private keys don’t match. Maybe one of them is wrong

  • Private key overwrite add once

ssh-agent bash
ssh-add ~/.ssh/id_rsa_gitee
Copy the code
  • If no, repeat the preceding steps