git 多账号配置
2016-08-12 15:51
309 查看
第一步:生成密钥
$ cd ~/.ssh
$ ssh-keygen -t rsa -C "user1@email.com"
出现:
Generating public/private rsa key pair.
Enter file in which to save the key (/u//.ssh/id_rsa):
以后可能多个帐号,所以可以存放在是/u//.ssh/id_rsa.user1
在.ssh下将会出现两个文件 id_rsa.user1 和 id_rsa.user1.pub
第二步:添加公钥
将id_rsa***.pub的公钥信息复制到对应gitlab的添加ssh
key里
第三步:添加密钥
因为默认只读取id_rsa,为了让SSH识别新的私钥,需将其添加到SSH agent中:
ssh-add .ssh/id_rsa_***
如果出现Could not open a connection to your authentication agent的错误,试用以下命令:
ssh-agent bash
ssh-add .ssh/id_rsa_***
第四步:多个帐号对应同个gitlab的情况--修改config内的别名
在~/.ssh目录下找到config文件,如果没有就创建:
touch config
内容可以是:
Host githubuser1
HostName github.com
PreferredAuthentications publickey
identityFile ~/.ssh/id_rsa_user1
Host
githubuser2
HostName github.com
PreferredAuthentications publickey
identityFile ~/.ssh/id_rsa_user2
第五步:测试
$ ssh -T git@githubuser1
$ cd ~/.ssh
$ ssh-keygen -t rsa -C "user1@email.com"
出现:
Generating public/private rsa key pair.
Enter file in which to save the key (/u//.ssh/id_rsa):
以后可能多个帐号,所以可以存放在是/u//.ssh/id_rsa.user1
在.ssh下将会出现两个文件 id_rsa.user1 和 id_rsa.user1.pub
第二步:添加公钥
将id_rsa***.pub的公钥信息复制到对应gitlab的添加ssh
key里
第三步:添加密钥
因为默认只读取id_rsa,为了让SSH识别新的私钥,需将其添加到SSH agent中:
ssh-add .ssh/id_rsa_***
如果出现Could not open a connection to your authentication agent的错误,试用以下命令:
ssh-agent bash
ssh-add .ssh/id_rsa_***
第四步:多个帐号对应同个gitlab的情况--修改config内的别名
在~/.ssh目录下找到config文件,如果没有就创建:
touch config
内容可以是:
Host githubuser1
HostName github.com
PreferredAuthentications publickey
identityFile ~/.ssh/id_rsa_user1
Host
githubuser2
HostName github.com
PreferredAuthentications publickey
identityFile ~/.ssh/id_rsa_user2
第五步:测试
$ ssh -T git@githubuser1
相关文章推荐
- Mybatis学习笔记---day04 mybatis与spring整合
- AngularJs过滤器
- 06.数组
- CGRect, CGPoint,CGSize,CGAffineTransform,UIEdgeInsets,UIOffset与NSValue的相互转换
- 分析Java的hashCode 和 hashCode在HashMap的底层数据结构的应用
- 那些鲜为人知的JavaScript 技巧
- Java连接MySQL实现增删改查
- 根据入栈顺序判断出栈序列正确与否
- POJ 1258 Agri-Net 【MST,Prime算法】
- 20160812
- 求最长的升序子序列 并将最长的升序子序列输出
- Android studio 中添加 .so 文件
- Apache2 httpd.conf 配置详解(一)
- HYSBZ 1444 有趣的游戏 AC自动机+概率DP+高斯消元
- [leetcode]224. Basic Calculator --JavaScript 代码
- atoi()函数的实现
- Codeforces Round #367 (Div. 2) C Hard problem(DP)
- 利用wireshark对zigbee及6lowpan进行抓包分析
- RBTree
- mysql 将null转为0