您的位置:首页 > 其它

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: