使用SSH CONFIG
github200 阅读0 评论
生成秘钥
ssh-keygen -t rsa -C "注册的gitlab邮箱" -f ~/.ssh/gitlab_id_rsa
ssh-keygen -t rsa -C "注册的github邮箱" -f ~/.ssh/github_id_rsa
配置~/.ssh/config文件
只需配两项,其他参数默认即可(注,如果有port,需要填上)
···
Host github
HostName github.com
IdentityFile ~/.ssh/github_id_rsa
Host gitlab
HostName gitlab.com
IdentityFile ~/.ssh/gitlab_id_rsa
···
添加新增的rsa到名字列表
这一步很重要,不然会找不到个性化的rsa默认使用系统的rsa
ssh-add ~/.ssh/gitlab_id_rsa
ssh-add ~/.ssh/github_id_rsa
执行ssh-add时出现 Could not open a connection to your authentication agent,
可以先执行ssh-agent bash,然后再执行ssh-add即可。
将public key字符串复制添加到GitHub和gitlab的SSH key中
测试
ssh -T git@github.com
打印以下信息代表连接github成功:
Hi ****! You've successfully authenticated, but GitHub does not provide shell access.
ssh -T git@gitlab首页地址
打印以下信息代表连接gitlab成功:
Welcome to GitLab, @****!
相关文章
评论 (0)
- 还没有评论,来第一条吧。