当前位置:   article > 正文

GitHub | 一台电脑怎么设置多个GitHub账号的ssh key?_如果一个机器的公钥被上传在多个github上

如果一个机器的公钥被上传在多个github上

使用win10的git bash生成ssh key:$ ssh-keygen -t rsa -C "jimmyMall@xxxe.com"
需要把公钥放到github自己账号下,过程略。
本过程在win10和Ubuntu上测试通过。

1.本机设置

(1)win10中命令在git bash中操作。

$ cat ~/.ssh/config
# github1
Host mio
  HostName github.com
  User miostudio
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/gitee_id_rsa

# github 2
Host eve
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

使用了 已有rsa文件。
说明:

  • Host 后面随便写,这个后面要用,取一个好理解、好记的名字。
  • HostName不能写错,可以是其他仓库网站的网址。
  • UserName是自己的github账号。可以省略
  • 最后一行是rsa私钥地址。生成的时候可以指定名字,最好就放到默认为位置。
  • 除了第一行顶格写,其他前面要空格,这个很重要,貌似tab不行?
  • 如果多个账号,则复制粘贴多段,每段用空行隔开。

(2) 测试新地址

$ ssh -T git@mio
Enter passphrase for key '/c/Users/admin/.ssh/gitee_id_rsa':
Hi miostudio! You've successfully authenticated, but GitHub does not provide shell access.
  • 1
  • 2
  • 3

2. git remote 修改

$ git remote -v
origin  https://github.com/miostudio/vue_learn.git (fetch)
origin  https://github.com/miostudio/vue_learn.git (push)

修改新地址:
$ git remote set-url origin git@mio:MioStudio/vue_learn.git 

$ git remote -v
origin  git@mio:MioStudio/vue_learn.git (fetch)
origin  git@mio:MioStudio/vue_learn.git (push)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

注意,修改的新地址中@前是固定的,@后是config中定义的第一行Host。冒号后面是用户名和仓库名,最后用.git结尾。

3. 推送

一个电脑只需要配置一次配置文件。
一个仓库只需要修改一次路径。
后面就正常的推送了,命令行或图形界面都可以。
$ git push origin master

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/955378
推荐阅读
相关标签
  

闽ICP备14008679号