整理GIT(ssh)多用户配置

目标

  1. 整理GIT(ssh)支持多用户管理

配置本地github账户

  1. 创建rsa密钥
    cd ~/.ssh

    ssh-keygen -t rsa -C "xxxx@email.com"
    Generating public/private rsa key pair.
    Enter file in which to save the key (/c/Users/Dell/.ssh/id_rsa): /c/Users/Dell/.ssh/local/id_rsa_local
  2. 复制密钥到github ssh中

配置私服gitlab账户

  1. 创建rsa密钥
    cd ~/.ssh

    ssh-keygen -t rsa -C "xxxx@email.com"
    Generating public/private rsa key pair.
    Enter file in which to save the key (/c/Users/Dell/.ssh/id_rsa): /c/Users/Dell/.ssh/ruoze/id_rsa_ruoze
  2. 复制密钥到github ssh中

配置config

  1. 在.ssh目录下创建config文件,*注意仅仅是 config *
  2. 在配置文件中添加如下配置
    # github 针对github的配置
    Host github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/local/id_rsa
    # ruoze
    Host git.ruozedata.com
    HostName git.ruozedata.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/ruoze/id_rsa_ruoze
    说明:
    Host:包含端口,如果端口是80就不显示,即 git@host @ 后面的部分
    HostName:不包含端口,此处指定Host对应的具体域名
    User:说明该配置的用户是git,即 git@hostname @ 前面的部分
    Port:git端口

测试

ssh -T git@host
Welcome to GitLab, @Red!
Author: Red
Link: http://yoursite.com/2018/11/21/archives/git/git-1/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.