git使用指定的ssh-key名

git ssh

  1. 以管理员身份运行powershell

  2. 使用你的github账号邮箱生成一个ssh key

    ssh-keygen -t ed25519 -C "your@mail.com" -f "你想让github ssh key存放的路径"
    

    ![在这里插入图片描述]( https://img-blog.csdnimg.cn/af06d200518047019757de340445b7f9.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM0NTQ4MDc1,size_16,color_FFFFFF,t_70#pic_center)

  3. 查看是否设置ssh-agent,如下图情况则为ssh-agent未运行

    ssh-add -l
    

    在这里插入图片描述

  4. 运行ssh-agent

     Set-Service ssh-agent -StartupType Automatic
     Start-Service ssh-agent
     Get-Service ssh-agent
    

    ![在这里插入图片描述]( https://img-blog.csdnimg.cn/69820b8a9b9749b9af4f0f17657ce827.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM0NTQ4MDc1,size_16,color_FFFFFF,t_70#pic_center)

  5. 将你的github ssh key添加到ssh agent

    ssh-add "C:\Users\mayu3\.ssh\id_rsa-remote-ssh-github"
    

    在这里插入图片描述

  6. 复制你的github ssh key的私钥到剪贴板

    Get-Content C:\Users\mayu3\.ssh\id_rsa-remote-ssh-github.pub | Set-Clipboard
    

    在这里插入图片描述

  7. 登录你的GitHub账户,添加ssh key的公钥![在这里插入图片描述]( https://img-blog.csdnimg.cn/c179a46d365d4560959cb03dd7ce3d9e.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM0NTQ4MDc1,size_16,color_FFFFFF,t_70#pic_center)

  8. 点击New SSH key![在这里插入图片描述]( https://img-blog.csdnimg.cn/32c6717ce11a413ca1f8db18faba9ce7.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM0NTQ4MDc1,size_16,color_FFFFFF,t_70#pic_center)

  9. 填写Title和Key![在这里插入图片描述]( https://img-blog.csdnimg.cn/b4f1062d6e434cd2a340cafc076d3bbd.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM0NTQ4MDc1,size_16,color_FFFFFF,t_70#pic_center)

  10. 添加后的效果![在这里插入图片描述]( https://img-blog.csdnimg.cn/2caf765c96ee4f64952fece955905597.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM0NTQ4MDc1,size_16,color_FFFFFF,t_70#pic_center)

  11. 编辑~/.ssh/config文件添加以下内容

    Host github.com
        Hostname        github.com
        IdentityFile    ~/.ssh/id_rsa_custom
        IdentitiesOnly yes
    

    ![在这里插入图片描述]( https://img-blog.csdnimg.cn/f29a39968243460e9826c397dbab19d0.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM0NTQ4MDc1,size_16,color_FFFFFF,t_70#pic_center)

  12. 添加remote

    # notessh 是你为remote起的别名,随便起
    # git@github.com:sober-orange/mynote.git 是你的仓库ssh链接
    git remote add notessh git@github.com:sober-orange/mynote.git
    
  13. 提交代码

    # 以下两行命令等价
    git push --set-upstream notessh main
    git push -u notessh main
    

    ![在这里插入图片描述]( https://img-blog.csdnimg.cn/faa73b82d8204543b58581648f2543a7.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM0NTQ4MDc1,size_16,color_FFFFFF,t_70#pic_center)

参考文献

https://www.163.com/dy/article/GHCG1C5B0511DSSR.html

posted @ 2021-08-17 18:31  没有B树  阅读(197)  评论(0)    收藏  举报
图像的替代文本-知乎