git如何配置多个帐户

git如何配置多个帐户

*在配置git多用户时,把全局用户配置

查看配置信息
git config --list
添加全局用户信息
git config --global user.name “用户名”
git config --global user.email “邮箱”
#删除全局用户信息
git config --global --unset user.name
git config --global --unset user.email

1 打开git bash命令行,切换到ssh目录

cd ~/.ssh

2.生成github.com,gitlab.com bitbucket 等对应的私钥公钥

$ ssh-keygen -t rsa -C “注册的邮件”
注:生成id_rsa私钥公钥时需要命不同文件名

3.拷贝公钥账户到github 和gitlab bitbucket 等的SSH keys中

4.在.ssh目录创建config文本文件并完成相关配置

Host      主机别名
HostName  服务器真实地址 (域名|ip)
IdentityFile  私钥文件路径
PreferredAuthentications  认证方式
User  用户名
 cd ~/.ssh
> touch config
> vi config
Host github.com 别名
 User 用户名
 Hostname github.com
 PreferredAuthentications publickey
  IdentityFile ~/.ssh/id_rsa_github 注:你生成的私钥
  
Host gitlab 别名
User 用户名
Hostname gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_gitlab 注:你生成的私钥

 Host bitbucket 为你的项目仓库地址(域名|ip)
 User 账户用户名
 HostName bitbucket.com
 PreferredAuthentications publickey
 IdentityFile ~/.ssh/id_rsa_bitbucket 注:你生成的私钥

5.将密钥加入密钥管理器

ssh-add ~/.ssh/id_rsa_github
ssh-add ~/.ssh/id_rsa_gitlab
ssh-add ~/.ssh/id_rsa_bitbucket
遇到Could not open a connection to your authentication agent.提示,输入一下命令,在进行ssh-add
ssh-agent bash

6.验证

ssh -T git@github.com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值