一个GitLab,一个GitHub,两个账号地址不同,需要添加两个ssh,网上找了几篇,操作成功以后做个汇总。
1、打开ssh文件夹:
cd ~/.ssh/
2、添加新的ssh密钥:
ssh-keygen -t rsa -C "youremail@app.com"
3、重命名,若一路回车名字和密码都可以不写,默认会在~/.ssh/目录下生成id_rsa。为了区分,第一个回车后可以设置文件名称:
Enter file in which to save the key (/root/.ssh/id_rsa):~/.ssh/文件名
4、复制密钥:
cat id_rsa_mine.pub
5、密钥添加到自己的git中
6、创建config文件:
touch ~/.ssh/config
7、config文件下添加如下信息
# gitlab
Host http:***.***.**.**/
HostName http://124.128.23.70/
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
user git
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_mine
user git
8、验证连接
ssh -T git@github.com
GitLab返回“Welcome to GitLab,##!”表示调通
GitHub返回“Hi BeginMan! You've successfully authenticated, but GitHub does not provide shell access.”表示调通
链接不成功时检测出错信息
ssh -vT git@gihub.com