1、新建user2的SSH Key
#新建SSH key:
$ cd ~/.ssh
$ ssh-keygen -t rsa -C "mywork@email.com"
# 新建工作的SSH key
# 设置名称为id_rsa_work
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): id_rsa_work
2、新密钥添加到SSH agent中因为默认只读取id_rsa,为了让SSH识别新的私钥,需将其添加到SSH agent中:
$ ssh-add ~/.ssh/id_rsa_work
如果出现Could not open a connection to your authentication agent的错误,就试着用以下命令:
$ ssh-agent bash
$ ssh-add ~/.ssh/id_rsa_work
3、修改config文件
在~/.ssh目录下找到config文件,如果没有就创建:
$ vim config
----------------------------------------------
# 该文件用于配置私钥对应的服务器
# Default github user(first@mail.com)
Host "github.com"
HostName "github.com"
User "git"
IdentityFile "~/.ssh/id_rsa"
# second user(second@mail.com)
# 建一个github别名,新建的帐号使用这个别名做克隆和更新
Host "github2"
HostName "github.com"
User "git"
IdentityFile "~/.ssh/id_rsa_work"
----------------------------------------------
测试
$ ssh github2
#新建SSH key:
$ cd ~/.ssh
$ ssh-keygen -t rsa -C "mywork@email.com"
# 新建工作的SSH key
# 设置名称为id_rsa_work
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): id_rsa_work
2、新密钥添加到SSH agent中因为默认只读取id_rsa,为了让SSH识别新的私钥,需将其添加到SSH agent中:
$ ssh-add ~/.ssh/id_rsa_work
如果出现Could not open a connection to your authentication agent的错误,就试着用以下命令:
$ ssh-agent bash
$ ssh-add ~/.ssh/id_rsa_work
3、修改config文件
在~/.ssh目录下找到config文件,如果没有就创建:
$ vim config
----------------------------------------------
# 该文件用于配置私钥对应的服务器
# Default github user(first@mail.com)
Host "github.com"
HostName "github.com"
User "git"
IdentityFile "~/.ssh/id_rsa"
# second user(second@mail.com)
# 建一个github别名,新建的帐号使用这个别名做克隆和更新
Host "github2"
HostName "github.com"
User "git"
IdentityFile "~/.ssh/id_rsa_work"
----------------------------------------------
测试
$ ssh github2









