如果需要同时管理自己的github上的项目和团队内部的gitlab上的项目,我们就需要配置多个ssh密钥。
使用ssh-keygen -b 1024 -r rsa命令可以生成密钥对(id_rsa,id_rsa.pub),在家目录的.ssh文件中。将公钥(id_rsa.pub中的内容)添加到gitlab(该身份对应的托管平台)上即可。
同样的,生成自己用于github的密钥对,这里命名为github_rsa、github_rsa.pub。这两对密钥对均放在.ssh文件中,这里添加一个配置文件config即可解决多密钥问题。
config文件内容如下:
Host http://***.cn/
port ****
IdentityFile /c/Users/Administrator/.ssh/id_rsa
Host github.com
IdentityFile /c/Users/Administrator/.ssh/github_rsa
此时.ssh下将有6个文件(config github_rsa github_rsa.pub id_rsa id_rsa.pub known_hosts)。
如果要换个电脑工作,安装git后,可以将.ssh文件夹拷贝到新机器的用户家目录,然后执行以下命令:
git config --global user.name "123"
git config --global user.email "123@test.com"
配置完成即可。
看看当前配置,使用命令git config user.name,git config user.email。