背景
以前用Github,Push很正常,后来公司的项目要在Gitee(码云)上协同开发,就从新配置了ssh-key,致使了Github的ssh-key就失效了。如下说说我是如何解决这个问题的。git
解决方法
须要给ssh配置多个key,不用名对应不一样key文件。github
一、建立config文件shell
cd .ssh touch config
二、建立ssh-key
ssh-keygen -t rsa -f ~/.ssh/id_rsa.别名 -C “邮箱地址“
示例ssh
ssh-keygen -t rsa -f ~/.ssh/id_rsa.github -C “xxx@xxx.com“
ssh-keygen -t rsa -f ~/.ssh/id_rsa.gitee -C “xxx@xxx.com“
ssh-key文件已经生成到指定路径了,那么接下来咱们来配置一下。ide
三、配置(仅供参考)
# second user(xxx@xxx.com)
# 建一个github别名,新建的账号使用这个别名作克隆和更新
Host github
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa.github
# second user(xxx@xxx.com)
# 建一个gitee别名,新建的账号使用这个别名作克隆和更新
Host gitee
HostName gitee.com
User git
IdentityFile ~/.ssh/id_rsa.gitee
Host是别名。若是只是为了区分github、gitee等,为了方便使用,建议和HostName一致,这样在clone git的时候不用考虑修改hostname。code
若是只是为了区分github、gitee等,
四、经过别名来使用
ssh -T gitee
返回:Welcome to Gitee.com, xxx!开发
表示成功it
ssh -T github
返回:Hi xinwen-mao! You've successfully authenticated, but GitHub does not provide shell access.配置
表示成功rsa