1. 程式人生 > >GIT使用不同的郵箱秘鑰連接gitlab,oschina,和github 等多臺服務器

GIT使用不同的郵箱秘鑰連接gitlab,oschina,和github 等多臺服務器

GIT linux ssh gitlab github

實例:
一、根據郵箱生產不同秘鑰

  1. 生產服務器gitlab秘鑰值
    ssh-keygen -t rsa -C [email protected]
    key值名稱:id_rsa_lab id_rsa_lab.pub

  2. 生產github秘鑰值
    ssh-keygen -t rsa -C "[email protected]"
    key值名稱:id_rsa_hub id_rsa_hub.pub

二、將密鑰添加到ssh-agent

        當前.ssh/下打開 git bash  執行命令ssh-add  id_rsa_lab
        如果出現: Could not open a connection to your authentication agent.
        執行 exec ssh-agent bash 後執行
        ssh-add  id_rsa_lab
        ssh-add  id_rsa_hub

當然如果這裏出現什麽問題,你也可以用 ssh-add -d 來刪除某個id_rsa 查看用ssh-add -l

三、添加ssh配置文件
在./ssh/ 文件夾下的config文件中添加:
#gitlab
Host git.xxx.com
HostName git.xxx.com
User git
IdentityFile ~/.ssh/id_rsa_lab
#github
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_hub

四: 將分別將密鑰添加到gitlab、github 的ssh key中

五:測試連接是否成功

            ssh -T [email protected]
            ssh -T [email protected]

GIT使用不同的郵箱秘鑰連接gitlab,oschina,和github 等多臺服務器