zoukankan      html  css  js  c++  java
  • Git多密钥配置

    参考的博客

    生成密钥

    打开git bash

    ssh-keygen -t rsa -C "你的邮箱" -f ~/.ssh/id_rsa_gitee
    ssh-keygen -t rsa -C "你的邮箱" -f ~/.ssh/id_rsa_github
    

    添加密钥到ssh-agent中

    Git默认读取的文件文件名为id_rsa,因此我们需要将生成的密钥添加到ssh-agent中。

    # 添加密钥地址到ssh-agent
    ssh-add ~/.ssh/id_rsa_github
    ssh-add ~/.ssh/id_rsa_gitee
    # 如果出错,可以使用这条命令,再执行上方代码
    ssh-agent bash
    

    编写配置文件

    编写config文件(~/.ssh目录下),若没有则自行新建。

    # github
    Host github.com
    HostName github.com
    PreferredAuthentications publickey  
    IdentityFile ~/.ssh/id_rsa_github  
    # gitee
    Host gitee.com
    HostName gitee.com
    PreferredAuthentications publickey  
    IdentityFile ~/.ssh/id_rsa_gitee
    # 相关参数
    # Host:对识别的模式,进行配置对应的主机名和ssh文件
    # HostName : 登录主机的主机名
    # PreferredAuthentications :设置登录方式(publickey为使用密钥登录,password为使用密码登录)
    # IdentityFile :私钥全路径名
    

    查看密钥并在git/gitee添加公钥

    查看生成的公钥

    cat ~/.ssh/id_rsa_gitee.pub
    

    复制公钥到git/gitee即可

    github同理

    最后测试下是否添加成功

    ssh -T git@github.com
    ssh -T gitee@github.com
    
  • 相关阅读:
    一天一个Linux命令--find
    一天一个Linux命令--dhclient
    一道CTF题引发的思考——SSI注入
    netcat的简单使用(一)
    文件头类型
    windows10禁用更新方法
    Burpsuite 之intruder
    localstorage sessionstorage和cookie的区别
    js中的迭代方法-every, some, filter, map, forEach
    前端日志分类
  • 原文地址:https://www.cnblogs.com/shouyaya/p/15356041.html
Copyright © 2011-2022 走看看