zoukankan      html  css  js  c++  java
  • git多账户配置

        1.生成公钥,私钥
    在Git使用中经常会碰到多用户问题,例如:你在公司里有一个git账户,在github上有一个账户,并且你想在一台电脑上同时对这两个git账户进行操作,此时就需要进行git多用户配置。
        首先配置不同的SSH KEY,使用ssh-keygen命令产生两个不同的SSH KEY,进入.ssh目录:
    #切换到当前登陆用户的.ssh目录
    cd ~/.ssh  
    #使用自己github的注册邮箱产生SSH KEY
    ssh-keygen -t rsa -C "mygithub@email.com"  
    #github的SSH KEY
    Enter file in which to save the key (/Users/ltc/.ssh/id_rsa): /c/Users/Administrator/.ssh/id_rsa_github
    id_rsa_github
    #将ssh key添加到SSH agent中 
    ssh-add ~/.ssh/id_rsa_github

    实例图如下:

    *注: 如果执行 ssh-add 时显示错误 Could not open a connection to your authentication agent. 那么执行

    eval `ssh-agent -s`

    后重新执行 ssh-add 那条命令即可。

    成功提示如下:

    $ ssh-add ~/.ssh/id_rsa_github
    Identity added: /c/Users/Administrator/.ssh/id_rsa_github (/c/Users/Administrator/.ssh/id_rsa_github)

    如图所示

    2.修改config配置文件指定账户使用的公钥

    Host github.com
       User git
       Hostname github.com
       IdentityFile ~/.ssh/id_rsa_github

    3.在生成ssh key之后,需要分别在github的profile中编辑SSH KEY,以github为例:

    在图中添加Title,可以随便写:
    将.ssh目录下对应的id_rsa_github.pub中的内容拷到Key中,点击Add SSH key按钮即可。

    4.测试下看看成功与否

    $ ssh -T git@github.com
    Hi running-fly! You've successfully authenticated, but GitHub does not provide shell access.
  • 相关阅读:
    MVC模式简单介绍
    Android AES加密算法及事实上现
    01背包问题
    C++继承经典样例
    [React] React Fundamentals: Using Refs to Access Components
    [React] React Fundamentals: Owner Ownee Relationship
    [React] React Fundamentals: State Basics
    [React] React Fundamentals: First Component
    [Javascript] Lodash: Refactoring Simple For Loops (_.find, _.findLast, _.filter)
    [Javascript] Create an Array concatAll method
  • 原文地址:https://www.cnblogs.com/zxqblogrecord/p/10123172.html
Copyright © 2011-2022 走看看