美文网首页
Git多账户配置

Git多账户配置

作者: 一大只土豆 | 来源:发表于2017-09-05 21:08 被阅读0次

日常开发过程中,我们可能遇到需要在同一电脑上配置多个Git账户的情况;github、公司的git服务器等,这时候我们需要配置多个ssh。以Mac为例。

1.取消全局的账户配置

查看全局账户

git config --global user.name

如果存在,取消全局设置

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

2.创建不同user的ssh key

# 新建ssh key 
cd ~/.ssh 
ssh-keygen -t rsa -C "new_user@email.com"  # 生成新的ssh key
# 设置新的ssh key的名称
Enter file in which to save the key (/Users/{username}/.ssh/id_rsa): id_rsa_oschn

3.新密钥添加到ssh agent中

默认只添加了id_rsa,因此需要将新的ssh key 添加

ssh-add ~/.ssh/id_rsa_oschn

如果添加报错:Could not open a connection to your authentication agent,尝试以下命令

ssh-agent bash
ssh-add ~/.ssh/id_rsa_oschn

4.修改config文件

在~/.ssh目录下找到config文件,如果没有就创建

touch config #创建config文件

修改config 文件

# 该文件用于配置私钥对应的服务器
# corporation gitlib user(xxx@corp.com.cn)
Host git@git.corpxxx.com
HostName https://git.corpxxx.com
User git
IdentityFile ~/.ssh/id_rsa

# second user(user@xxx.com)
# OSChina
Host git@gitee.com
HostName https://gitee.com
User git
# PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_oschn

5.测试

ssh -T git@gitee.com

6.其他

在使用idea的时候,可能出现命令行可以clone 代码,但是idea里面不能clone代码的情况,检查一下配置:
Version Control -> Git -> SSH executable: Native

相关文章

  • Git基本使用命令

    Git配置 Git最小配置 配置全局账户,该账户对所有Git仓库都有效 配置局部账户,该账户对当前Git仓库有效 ...

  • Git 葵花宝典

    账户配置 配置全局账户,对所有 Git 仓库有效 配置局部账户,只对当前 Git 仓库有效 查看全局配置 查看局部...

  • git 多账户配置

    1、生成多个密钥 ssh-keygen -t rsa -C "邮箱" -f 文件名 2、在 .ssh 目录下创建 ...

  • git 多账户配置

    环境 MacOS 检查是否已有全局账户设置: 如果都没有返回值,就说明没有已配置的 git 账户,否则请删除账户信...

  • Git多账户配置

    日常开发过程中,我们可能遇到需要在同一电脑上配置多个Git账户的情况;github、公司的git服务器等,这时候我...

  • git 多账户配置

    在Git使用中经常会碰到多用户问题,例如:你在公司里有一个git账户,在github上有一个账户,并且你想在一台电...

  • GIT快速入门

    基本配置 下载软件 git-scm Git配置用户名与邮箱 配置公钥 多账户配置(可跳过) 传送门: Window...

  • 本地配置Git多账户

    最近遇到这样一种情况,在一台电脑上需要设置两个git账号。两个账号都有其作用。所以记录一下设置多账号的过程 1. ...

  • Git多账户配置教程

    安装Git后,就可以进行配置:用户名,邮箱,SSH密钥等。也许你有多个Git账号,分别对应github.com、c...

  • Git多账户切换配置

    1、手动切换 gitlab和github项目切换时, github上多个项目账户不同时,都需要切换用户。 但是这个...

网友评论

      本文标题:Git多账户配置

      本文链接:https://www.haomeiwen.com/subject/jkiyjxtx.html