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
    
  • 相关阅读:
    luoguP1919 A*B Problem升级版 ntt
    luogu[愚人节题目3]现代妖怪殖民地 NTT
    FFT 快速傅里叶变换 学习笔记
    十二省联考 爆0记
    # NOI.AC省选赛 第五场T1 子集,与&最大值
    2019.6.16完成classstack任务
    USACO-集合
    USACO-修理牛棚
    dij模板
    洛谷P1948 [USACO08JAN]电话线Telephone Lines
  • 原文地址:https://www.cnblogs.com/shouyaya/p/15356041.html
Copyright © 2011-2022 走看看