首先把公钥和私钥都按以下方式命名好,并且放到.ssh目录下,方便管理(注意公钥和私钥两个文件一个都不能少)
~/.ssh/project1_rsa
~/.ssh/project1_rsa.pub
~/.ssh/project2_rsa
~/.ssh/project2_rsa.pub
~/.ssh/project3_rsa
~/.ssh/project3_rsa.pub
然后在.ssh文件夹下新一个config文件,内容如下:
#Host可以看作是一个你要识别的模式,对识别的模式,进行配置对应的的主机名和ssh文件
Host “project1″
HostName “github.com” #要登录主机的主机名
User “git” #登录名
IdentityFile “~/.ssh/project1_rsa” #指明上面User对应的identityFile路径
Host “project2″
HostName “10.9.210.240″
User “git”
IdentityFile “~/.ssh/project2_rsa”