一)生成SSH-key
// github ---- SSH-key
ssh-keygen -t rsa -C "aaa@xx.com" -f ~/.ssh/github_id_rsa
// gitlab ---- SSH-key
ssh-keygen -t rsa -C "bbb@xx.com" -f ~/.ssh/gitlab_id_rsa
// gitee ---- SSH-key
ssh-keygen -t rsa -C "ccc@xx.com" -f ~/.ssh/gitee_id_rsa
二)配置config文件(可选步骤)
- cd ~/.ssh
- touch ~/.ssh/config
- 添加如下配置:
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id_rsa
# gitlab
Host gitlab.com
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitlab_id_rsa
# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee_id_rsa
三)上传public-key(自行上传至目标网站)
- cd ~/.ssh
- cat github_id_rsa.pub
- cat gitlab_id_rsa.pub
- cat gitee_id_rsa.pub
// GitHub
复制"github_id_rsa.pub"文件内容,添加至GitHub
// GitLab
复制"gitlab_id_rsa.pub"文件内容,添加至GitLab
// Gitee
复制"gitee_id_rsa.pub"文件内容,添加至Gitee
四)验证SSH
// GitHub
ssh -T git@github.com
// GitLab
ssh -T git@gitlab.your_gitlab_ip_address.com
// Gitee
ssh -T git@gitee.com
// GitHub
"Hi xxxx! You've successfully authenticated, but GitHub does not provide shell access."
// GitLab
"Welcome to GitLab, (xxxx)!"
// Gitee
"Hi xxxx! You've successfully authenticated, but Gitee does not provide shell access."
// GitHub
"git@github.com: Permission denied (publickey)."
// GitLab
"git@gitlab.com: Permission denied (publickey,keyboard-interactive)."
// Gitee
"git@gitee.com: Permission denied (publickey)."
// 由于上述通过"ssh-keygen -t rsa -C"生成的key是指定路径的,故此处需要手动执行如下指令:
ssh-agent -s
// GitHub
ssh-add ~/.ssh/github_id_rsa
// GitLab
ssh-add ~/.ssh/gitlab_id_rsa
// Gitee
ssh-add ~/.ssh/gitee_id_rsa
网友评论