zoukankan      html  css  js  c++  java
  • Git生成SSH秘钥

    第一步、首先,检查下自己之前有没有已经生成:

    在开始菜单中打开git下的git bash(当然,在其他目录下打开git bash也是一样的):
    然后执行

    ls -al ~/.ssh
    

    第二步、如果能进入到.ssh文件目录下 ,则证明,之前生成过.ssh秘钥,可以直接使用里面的秘钥。

    如果不能进入到.ssh文件目录下,则:

    检测下自己之前有没有配置:

    git config user.name和git config user.email(直接分别输入这两个命令)
    

    如果之前没有创建,则执行以下命令:

    git config –-global user.name "xxxxx"
    git config –-global user.email "xxx@xx.xxx"
    

    生成秘钥

    ssh-keygen -t rsa -C "上面的邮箱"
    

    代码参数含义:
    -t 指定密钥类型,默认是 rsa ,可以省略。
    -C 设置注释文字,比如邮箱。
    -f 指定密钥文件存储文件名。

    [root@localhost ~]# ssh-keygen -t rsa       <== 建立密钥对,-t代表类型,有RSA和DSA两种
    Generating public/private rsa key pair.
    Enter file in which to save the key (/root/.ssh/id_rsa):   <==密钥文件默认存放位置,按Enter即可
    Created directory '/root/.ssh'.
    Enter passphrase (empty for no passphrase):     <== 输入密钥锁码,或直接按 Enter 留空
    Enter same passphrase again:     <== 再输入一遍密钥锁码
    Your identification has been saved in /root/.ssh/id_rsa.    <== 生成的私钥
    Your public key has been saved in /root/.ssh/id_rsa.pub.    <== 生成的公钥
    The key fingerprint is:
    SHA256:K1qy928tkk1FUuzQtlZK+poeS67vIgPvHw9lQ+KNuZ4 root@localhost.localdomain
    The key's randomart image is:
    +---[RSA 2048]----+
    |           +.    |
    |          o * .  |
    |        . .O +   |
    |       . *. *    |
    |        S =+     |
    |    .    =...    |
    |    .oo =+o+     |
    |     ==o+B*o.    |
    |    oo.=EXO.     |
    +----[SHA256]-----+
    

    最后在.ssh目录下(C盘用户文件夹下)得到了两个文件:id_rsa(私有秘钥)和id_rsa.pub(公有密钥)

    第三步、如果想登陆远端,则需要将id_rsa.pub里的秘钥添加到远端。

    使用cat查看id_rsa.pub内容。

    $ cat ~/.ssh/id_rsa.pub
    

    第四步、测试

    再使用下面的命令测试是否成功

    ssh -T git@github.com
    

    看到如下显示代表成功

    Hi xxxxxxxx! You've successfully authenticated, but GitHub does not provide shell access.
    

    link

  • 相关阅读:
    108. Convert Sorted Array to Binary Search Tree
    How to check if one path is a child of another path?
    Why there is two completely different version of Reverse for List and IEnumerable?
    在Jenkins中集成Sonarqube
    如何查看sonarqube的版本 how to check the version of sonarqube
    Queue
    BFS广度优先 vs DFS深度优先 for Binary Tree
    Depth-first search and Breadth-first search 深度优先搜索和广度优先搜索
    102. Binary Tree Level Order Traversal 广度优先遍历
    How do I check if a type is a subtype OR the type of an object?
  • 原文地址:https://www.cnblogs.com/lixuejian/p/15637715.html
Copyright © 2011-2022 走看看