如何在本地配置多个ssh key

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_43215250/article/details/90174773
  1. 清除git的全局设置

    右键 -> Git Bash Here

    git config --global user.name "charles"
    git config --global user.email  "[email protected]"
    
  2. 生成秘钥

    生成 gerrit 的 ssh key

    ssh-keygen -t rsa -C '[email protected]' -f ~/.ssh/gerrit_egtest-rsa
    

    生成 github 的 ssh key

    ssh-keygen -t rsa -C '[email protected]' -f ~/.ssh/github-rsa
    
  3. 配置配置文件

    在~/.ssh/目录下新建一个名为config的文件,文件内容如下

    Host gerrit.xxx.xxx
        Port 29418
        User xxx
        HostName gerrit.xxx.xxx
        PreferredAuthentications publickey
        IdentityFile  ~/.ssh/gerrit_egtest-rsa
    Host github.com
        User charles
        HostName github.com
        PreferredAuthentications publickey
        IdentityFile  ~/.ssh/github-rsa
    

    配置文件参数:

    参数 说明
    Host 表示对应的的主机名和ssh文件
    HostName 要登录主机的主机名
    User 登录名
    IdentityFile User对应的identityFile路径

猜你喜欢

转载自blog.csdn.net/weixin_43215250/article/details/90174773