Skip to content

Instantly share code, notes, and snippets.

@whatedcgveg
Forked from suziewong/git.md
Created October 21, 2017 05:31
Show Gist options
  • Select an option

  • Save whatedcgveg/c2abb2f6e4e9f24d4903dc4ffa34a90d to your computer and use it in GitHub Desktop.

Select an option

Save whatedcgveg/c2abb2f6e4e9f24d4903dc4ffa34a90d to your computer and use it in GitHub Desktop.
Git的多账号如何处理? 1.同一台电脑多个git(不同网站的)账号 2.同一台电脑多个git(同一个网站的比如github的)多个账号

1.同一台电脑可以有2个git账号(不同网站的)

首先不同网站,当然可以使用同一个邮箱,比如我的github,gitlab,bitbucket的账号都是monkeysuzie[at]gmail.com 这时候不用担心密钥的问题,因为这些网站push pull 认证的唯一性的是邮箱 比如我的windows 上 2个账号一个gitlab 一个github (用的都是id_rsa)

host github
  hostname github.com
  Port 22
host gitlab.zjut.com
  hostname gitlab.zjut.com
  Port 65095

不需要指定key的位置。因为默认读取id_rsa了

2.同一台电脑有2个github账号?咋办

比如我服务器上模拟的2个用户

#monkeysuzie@gmail.com   我在gitlab的第一个账号suzie
host gitlab.zjut.com
    hostname gitlab.zjut.com
    Port 65095
    User suzie
    IdentityFile /home/suzie/.ssh/id_rsa
#  我在gitlab的第2个账号test
host gitlab-test.zjut.com
    hostname gitlab.zjut.com
    Port 65095
    User test
    IdentityFile /home/suzie/.ssh/id_rsa_second
#837368104@qq.com 我在github的账号 
host github-osteach.com
    hostname github.com
    Port 22
    User osteach
    IdentityFile /home/suzie/.ssh/id_rsa_second

备注

生成ssh key

ssh-keygen -m rsa -C "your mail" (当前目录) 然后可以命名默认id_rsa 或者id_rsa_second 把对应的pub放到公共服务器上。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment