How to Using Multiple GitHub Accounts

Generating SSH Keys for users

  • Generate a New SSH key(Replace AT whith @)

      ssh-keygen -t rsa -b 4096 -C "海云青飞 AT tuenhai.com"
    
  • Add SSH key to GitHub

      sudo apt install xclip
      xclip -sele clip ~/.ssh/id_rsa.pub
    

    Now you have the key copied, it's time to add it into GitHub

Edit ~/.ssh/config to add multiple host

tuenhai@linux:~$ vi ~/.ssh/config
Host github-tuenhai
    HostName github.com
    User git
    IdentityFile /path/to/github-tuenhai.id_rsa
    IdentitiesOnly yes

Host github-kige
    HostName github.com
    User git
    IdentityFile /path/to/github-kige.id_rsa
    IdentitiesOnly yes

Setting up Git on local computer

cd linuxtips
git init
git config user.name tuenhai
git config user.email 海云青飞 AT tuenhai.com (or name@users.noreply.github.com)
git remote add origin github-tuenhai:/tuenhai/linuxtips.git
git pull origin master

cd another-repo
git config user.name kige
git config user.email kige AT tuenhai.com (or name@users.noreply.github.com)
git remote add origin github-kige:/tuenhai/another-repo.git
git pull origin master
任何人生疑惑,请找 海云青飞 https://www.tuenhai.com