第一步生成ssh key
# 为 github 生成ssh-key -f 后面是指定生成文件名字 ssh-keygen -t rsa -C "github 绑定的邮箱" -f ~/.ssh/id_rsa_github # id_rsa_github.pub是github的ssh-key # 为gitlab生成ssh-key ssh-keygen -t rsa -C "gitlab 绑定的邮箱" -f ~/.ssh/id_rsa_gitlab # id_rsa_gitlab.pub是 gitlab 的 ssh-key
第二步核心步骤:~/.ssh文件夹下创建config文件(不带后缀名)
Host github HostName github.com User [email protected] PreferredAuthentications publickey AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/id_rsa_github Port 443 Host gitlab HostName gitlab.com IdentityFile ~/.ssh/id_rsa_gitlab
第三步 在gitlab、github官网根据提示加入ssh key
其中github注意需要将 SSH 密钥添加到 ssh-agent,具体方法在如下官方文档里
https://docs.github.com/cn/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
第四步 测试连接状态
ssh -T git@gitlab ssh -T git@github
标签:git,gitlab,rsa,一台,github,ssh,key,id From: https://www.cnblogs.com/alexjee/p/16628501.html