同一台电脑配置多个github账号使用

简介: 在同一台电脑配置多个github账号使用

SSH Key 配置


  • 打开 Git Bash。
  • 创建 SSH Key
    $ ssh-keygen -t rsa -C "注册邮箱"
    这将使用提供的电子邮件作为标签创建一个新的 SSH 密钥。
  • 当系统提示您“输入要在其中保存密钥的文件”时,按 Enter。这接受默认文件位置。
> Enter a file in which to save the key (/c/Users/you/.ssh/id_algorithm):[Press enter]
• 在提示符处,键入安全密码 回车跳过可以
> Enter passphrase (empty for no passphrase):[Press enter]



在用户主目录 /.ssh/ 下会生成有两个文件,id_rsa 是私钥,id_rsa.pub 是公钥 ,或者自定义名称


  1. 添加秘钥
    如果已经安装 GitHub Desktop,无需处理SSH 密钥:


其他的:


  1. 确保 ssh-agent 正在运行,或者手动启动它
# start the ssh-agent in the background$ eval"$(ssh-agent -s)"> Agent pid 59566


  1. 将秘钥添加到 ssh-agent,id_ed25519 替换为生成的私钥文件的名称。

$ ssh-add ~/.ssh/id_ed25519



配置两个账号


按照上面生成两个秘钥信息


设置 config


然后再在户主目录 /.ssh/ 下添加一个config文件,然后添加如下配置


每个用户设置不同的 Host


# github 用户 aHost a.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/a_id_rsa
# github 用户 bHost b.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/b_id_rsa


验证

$ ssh-Tgit@a.github.com
Hi a! You've successfully authenticated, but GitHub does not provide shell access.$ ssh -T git@b.github.comHi b!  You've successfully authenticated, but GitHub does not provide shell access.


重建 remote 在项目中使用,最重要的一步


删除原有的 remote,根据需要使用的用户,重新添加,例如在当前项目中使用a账号:

$ git remote rm origin
$ git remote add origin git@a.github.com:a/demo.git 
$ git push origin master
Everything up-to-date


或者直接在 .git/config中修改


$ cd ~// 进入根目录
$ vim .git/config  
## 修改 github.com --> a.github.com 为我们指定的 `HOST`[remote "origin"]
url =git@a.github.com:a/demo.git
fetch =+refs/heads/*:refs/remotes/origin/*


ps:


  1. 记得使用多账户的时候,取消git全局设置,在每个项目中设置使用的账号
    方式一:

1.取消global

git config --global--unset user.name
git config --global--unset user.email

2.设置每个项目repo的自己的user.email

git config  user.email "xxxx@xx.com"git config  user.name "a"

方式二:直接编辑 .git/config

  1. 配置其他账号类同,如 gitee,gitlab 等等
目录
相关文章
|
2月前
|
前端开发 NoSQL 数据库
如何设计 QQ、微信、微博、Github 等等,第三方账号登陆 ?(附表设计)
如何设计 QQ、微信、微博、Github 等等,第三方账号登陆 ?(附表设计)
36 1
|
8月前
|
Windows
在idea使用GitHub账号、Copilot异常
在idea使用GitHub账号、Copilot异常
153 0
|
10月前
|
存储 Linux 网络安全
Git 配置SSH,多个 Github 账号配置不同的SSH KEY(二)
Git 配置SSH,多个 Github 账号配置不同的SSH KEY
|
10月前
|
Shell 网络安全 开发工具
Git 配置SSH,多个 Github 账号配置不同的SSH KEY(一)
Git 配置SSH,多个 Github 账号配置不同的SSH KEY
|
11月前
|
搜索推荐 开发工具 数据安全/隐私保护
注册Github账号详细教程
一、GitHub的简介 1、大概介绍 GitHub是一个面向开源及私有软件项目的托管平台,因为只支持Git作为唯一的版本库格式进行托管,故名GitHub。 2、详细介绍 https://baike.baidu.com/item/github/10145341 二、如何注册自己的GitHub账户 1、进入github的官网 https://github.com/https://github.com/ 2、点击右上角注册按钮sign up,来到注册页面
450 0
|
算法 网络安全 数据安全/隐私保护
Github账号遭大规模暴力破解攻击
知名源代码仓库Github日前遭到大规模暴力破解密码的攻击,一些帐号被成功攻破。 “我们向受影响的用户发送了邮件,通知他们需要采取的措施。” “他们的密码被重置,个人访问令牌、OAuth授权和SSH密钥都已经被取消。”
333 0
Github账号遭大规模暴力破解攻击
|
开发工具 数据安全/隐私保护 git
Git_IDEA集成Github_设置GitHub账号
Git_IDEA集成Github_设置GitHub账号
173 0
Git_IDEA集成Github_设置GitHub账号
|
开发工具 数据安全/隐私保护 git
Github账号注册|学习笔记
快速学习Github账号注册
133 0
Github账号注册|学习笔记
|
网络安全
同机多Github账号配置多个SSH
有一些情况,我们需要在同一个机子配置多个github的ssh链接;
543 0
2022 github新建账号技巧
2022 github新建账号技巧
191 0
2022 github新建账号技巧