一、生成 ssh
mkdir ~/.ssh
ssh-keygen -t rsa -C "youremail@xxx.com(gitlab使用的邮箱)" -f ~/.ssh/id_rsa_gitlab
ssh-keygen -t rsa -C "youremail@xxx.com(github使用的邮箱)" -f ~/.ssh/id_rsa_github
二、链接gitlab
cd ~/.ssh

cat id_rsa_gitlab.pub
复制全部内容

将public key粘贴到gitlab下图位置,并保存


三、链接github
cd ~/.ssh

cat id_rsa_github.pub
复制全部内容

将public key粘贴到github下图位置,并保存


四、管理ssh keys
ssh-add ~/.ssh/id_rsa_github
ssh-add ~/.ssh/id_rsa_gitlab
touch ~/.ssh/config
vi ~/.ssh/config
#粘贴到 ~/.ssh/config
Host github.com
HostName github.com
User **** #写gitthub使用的邮箱
IdentityFile ~/.ssh/id_rsa_github #这里是Github生成sshkey的那个文件路径
Host gitlab #如果地址是公司的地址的话就直接写成公司的ip
HostName gitlab #如果地址是公司的地址的话就直接写成公司的ip
User **** #写gitlab使用的邮箱
IdentityFile ~/.ssh/id_rsa_gitlab #这里是GitLab生成sshkey的那个文件路径
五、结果&测试连接
ssh -T git@github.com
ssh -T git@gitlab.com

网友评论