公司有一个 Gitlab 账户,自己有两个 Github 账户,一个是 blog 一个是 project
配置公司账号
#切换到.ssh目录 cd ~/.ssh #使用自己的企业邮箱产生SSH KEY ssh-keygen -t rsa -C "yourworkname@workemail.com" #企业的可以使用id_rsa,也可以自己起名,例如:id_rsa_work Enter file in which to save the key (/Users/ltc/.ssh/id_rsa): id_rsa #将ssh key添加到SSH agent中 ssh-add ~/.ssh/id_rsa #tips:如果ssh-add执行出现could not open a connection to your authentication agent #需要先执行一条命令 ssh-agent bash 然后再次执行ssh-add就可以了 #因为工作需要,将公司的账户设置为global账户 git config --global user.workname git config --global user.workemail #将生成的id_rsa.pub内容添加到Gitlab的ssh key中 #测试:克隆一个需要权限认证的project,克隆成功即添加成功了
Host githubblog User ZhengJun2018 Hostname github.com IdentityFile ~/project/ZhengJunBlog/blogMe
Host blogServer User git Hostname 47.100.193.211 IdentityFile ~/project/ZhengJunBlog/blogMe IdentitiesOnly yes
#切换到.ssh目录 cd ~/.ssh #使用自己的企业邮箱产生SSH KEY ssh-keygen -t rsa -C "yourgithubname@github1email.com" #既然企业的使用了id_rsa,那Github的就自己起名,例如:id_rsa_github_yourname1 Enter file in which to save the key (/Users/ltc/.ssh/id_rsa): id_rsa_github_yourname1 #将ssh key添加到SSH agent中 ssh-add ~/.ssh/id_rsa_github_yourname1 #将生成的id_rsa_github_yourname1.pub内容添加到Github的ssh key中 #测试:ssh -T git@github.com
配置 project 账号
和 blog 一样,把生成的密钥另起名为你自己想起的任何名字,不重复就好,如:id_rsa_github_yourname2