• 【One by one系列】Git一步步生成SSH密钥,免密拉取远程仓库


    进入新环境,接手前人留下的电脑,使用的源代码管理工具是git,远程仓库是giteegit clone https://xxx.git

    remote:You do not have permission to pull from the repository via HTTPS

    大概是因为前人离职了,账号被移除了。windows下可以去控制面板-用户账户-凭据管理器-git:https://gitee.com,修改相关的用户名与密码。

    0.HTTPS与SSH的差别

    • HTTPS:使用httpsgit Bash里使用clone命令,但是每次fetchpush代码都需要输入账号和密码,这也是https方式的麻烦之处。

    • SSH:安全外壳协议,很多安全终端模拟软件都是使用的SSH协议登录远程服务,例如xshell,直接使用用户名,密码就能登录远程服务(网络连通的情况下),这也是SSH其中一种安全验证(基于口令),另外一种安全验证是基于密钥,git便是采用的这种方式与远程仓库进行交互。

      • 创建一对RSA公钥与私钥
      • 公钥上传至需要访问的服务器
      • 验证流程:
        • 客户端向服务器发出请求
        • 服务器将一个随机字符串发送给客户端
        • 客户端根据私钥加密这个随机字符串再发送给服务器
        • 服务器接受到加密后的字符串之后用公钥解密,如果正确就让客户端登录,否则拒绝。这样就不用使用密码了
        • 更多内容请查阅RSA算法。

    1.配置用户名

    git config --global user.name "randyfield"

    2.配置邮箱

    git config --global user.email "xx@qq.com"

    3.生成密钥

    ssh-keygen -t rsa -C "xx@qq.com
    
    Generating public/private rsa key pair.
    Enter file in which to save the key (/c/Users/Admin/.ssh/id_rsa):
    Created directory '/c/Users/Admin/.ssh'.
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /c/Users/Admin/.ssh/id_rsa
    Your public key has been saved in /c/Users/Admin/.ssh/id_rsa.pub
    The key fingerprint is:
    SHA256:Yva7uIuSpHF7P6bfvQDTA3pqu3Vi8Y2fhXlTTQliEA8 xx@qq.com
    The key's randomart image is:
    +---[RSA 3072]----+
    |         Eoo .   |
    |          + . . .|
    |      .    .   ..|
    |     . o       o |
    |    . O S     . .|
    |. o  = B + o .   |
    | = oo + * + +    |
    |. +..=o= = + .   |
    |   o=**++.=.     |
    +----[SHA256]-----+
    
    

    /c/Users/用户名/.ssh/id_rsa在C盘的路径

    4.公钥发送至gitee(github同理)

    C:UsersAdmin.ssh

    • 打开id_rsa.pub文件,里面就是公钥,复制

    • 设置-SSH公钥

    • 粘贴公钥

    • 保存

  • 相关阅读:
    Could not determine which “make” command to run. Check the “make” step in the build configuration
    crontab定时任务不执行的原因
    Linux 设置定时任务crontab命令
    Runtime.getRuntime.exec()执行linux脚本导致程序卡死问题
    Java并发编程:volatile关键字解析
    什么是ClassLoader
    GeoJson格式与转换(shapefile)Geotools
    Docker图形化工具——Portainer
    Docker安装mysql、nginx、redis、tomcat
    Docker中nginx+tomcat实现负载均衡
  • 原文地址:https://www.cnblogs.com/RandyField/p/12726448.html
Copyright © 2020-2023  润新知