zoukankan      html  css  js  c++  java
  • 配置多个ssh-key

    搞了三天没搞出来,还在男朋友面前哭了一场,真心觉得我只该吃屎,我好没用。哎。。
    首先在上一篇记录了如何生成ssh-key,并使本地可以通过ssh的方式克隆和推送项目。但如果你有个github账号,有个码云,有公司的gitlab,它们项目的ssh-key都不一样,此时就只能通过配置config使之可配多个key,当用ssh读取远程仓库的时候,自动去匹配ssh-key。

    **1. 生成多个新的ssh-key **

    $ ssh-keygen -t rsa -C "abc@email.com" //新建账号的ssh key ,enter后可重命名文件 e.g. id_rsa_github
    

    此时生成了id_rsa_github(私钥)和 id_rsa_github.pub(公钥)文件,将公钥文件的内容添加到你github上。码云等其他账号下的同上。

    2. 配置config文件,添加ssh key

    # github
    Host github #主机名 随便定义
    HostName github.com #主机地址
    User git  #代表git账户
    IdentityFile ~/.ssh/id_rsa_github #github的私钥
    # gitee
    Host gitee
    HostName gitee.com
    User git
    IdentityFile ~/.ssh/id_rsa_gitee
    #注意
    #1、代码前不要有空格
    #2、文件存为utf-8格式(无bom)
    #3、若git地址有端口号,须加入 
    Port 端口号
    

    3. 测试
    上边内容配置完成以后,测试是否可以连接成功。

    $ ssh -T github //测试github连接成功
    $ ssh -T gitee // 测试码云是否成功
    //如果不成功,可以使用ssh -T -v github 进行查看详情
    

    如果成功,此时可以看到
    enter image description here

    4. 通过ssh克隆推送项目

    $ git clone github:geekFeier/my-dream.git 
    // 因为config配置了Host的替代了Hostname,所以这里需要用github替代git@github.com,这里是个坑,我就是在这里吃了两天的屎
    
  • 相关阅读:
    2.Android之按钮Button和编辑框EditText学习
    《DSP using MATLAB》Problem 3.8
    《DSP using MATLAB》Problem 3.7
    《DSP using MATLAB》Problem 3.6
    《DSP using MATLAB》Problem 3.5
    《DSP using MATLAB》Problem 3.4
    《DSP using MATLAB》Problem 3.3
    《DSP using MATLAB》Problem 3.2
    《DSP using MATLAB》Problem 3.1
    《DSP using MATLAB》Problem 2.20
  • 原文地址:https://www.cnblogs.com/geekfeier/p/9815458.html
Copyright © 2011-2022 走看看