美文网首页
(SSH) GitHub、GitLab、Gitee添加SSH认证

(SSH) GitHub、GitLab、Gitee添加SSH认证

作者: 布呐呐u | 来源:发表于2021-09-03 10:15 被阅读0次

一)生成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
  • 接着输入“yes”
  • 若看到如下内容,则验证通过
// 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

相关文章

网友评论

      本文标题:(SSH) GitHub、GitLab、Gitee添加SSH认证

      本文链接:https://www.haomeiwen.com/subject/kinqwltx.html