zoukankan      html  css  js  c++  java
  • 配置github SSH公钥登录

    git的安装见https://www.cnblogs.com/liliyang/p/9829931.html

    配置git使用ssh密钥

    git支持https和git两种传输协议,github分享链接时会有两种协议可选:

     若git使用https协议,每次pull, push均提示要输入密码,使用git协议,然后使用ssh密钥对认证,即可实现免密

     
    配置git 通过ssh协议免密需要三个步骤:
    1、生成密钥对
    2、配置远程仓库(这里使用github)上的公钥
    3、把git的 remote url 修改为git协议(以上两个步骤初次设置过以后,以后使用都不需要再次设置,此步骤视以后项目的remote url而定,如果以后其他项目的协议为https则需要此步骤

     一、生成密钥对

    [root@kube-node1 ~]# ssh-keygen  
    Generating public/private rsa key pair.
    Enter file in which to save the key (/root/.ssh/id_rsa): 
    Enter passphrase (empty for no passphrase): 
    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:fO7pVFqZ464nC8H6B3pTE8cwPx2mTM0G8KJt7Or2L8o root@kube-node1
    The key's randomart image is:
    +---[RSA 2048]----+
    |          ...+   |
    |          o.. *  |
    |          .B.= . |
    |       o +..Bo.  |
    |        S =o*.   |
    |       ..*o= .   |
    |      ...o=..    |
    |      .o+=+o.    |
    |       +E*BBo    |
    +----[SHA256]-----+
    [root@kube-node1 ~]# ll .ssh/
    total 8
    -rw------- 1 root root 1679 Oct 23 11:32 id_rsa
    -rw-r--r-- 1 root root  397 Oct 23 11:32 id_rsa.pub

    [root@kube-node1 ~]# cat .ssh/id_rsa.pub
    ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDnjHeR/2hDtjMZKHND2kceUPSibuemNh0J/upA0DE/fmI8Ub52ZhJ1uY7STVntseR0HrJmed96KroD4uILE40ChKOwGZjptkFIWfZ+qCDYWpCqlUus2goiNlAj7WIYnlgzif/RSqn8wZNqqozi8JqU+g1gdWZCENU9C0ONeEwP83q1mATx26k8HGSN0Gg1V2zdKLUqEhEzQ/7FHEObDyZGT7NqAFfefgTLHr6lZslsHfqM7RdRBdf5zneSPSX264SgHIWFbgZKMyMVB+Um4jtdoQf2NpHAxIUfof1Ncn34KyPJ3PN2NEvkXhdKsSLohKiESe1hkYtDy+YagdqtwLf7 root@kube-node1

    要将这里的公钥复制添加到github公钥配置中

    二、添加公钥到自己的远程仓库(github)

    Title随便填写

     公钥复制到上述的Key中,点击Add SSH key

    在本地主机上测试:

    [root@kube-node1 ~]# ssh -T git@github.com
    The authenticity of host 'github.com (192.30.253.113)' can't be established.
    RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
    RSA key fingerprint is MD5:16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added 'github.com,192.30.253.113' (RSA) to the list of known hosts.
    
    Hi useyunwei! You've successfully authenticated, but GitHub does not provide shell access.

    三、修改git的remote url

     使用命令 git remote -v (需在事先clone的项目目录中执行)查看你当前的 remote url

     下面是在game-of-life项目的目录中执行

    [root@kube-node1 game-of-life]# git remote -v
    origin https://github.com/useyunwei/game-of-life.git (fetch)
    origin https://github.com/useyunwei/game-of-life.git (push)

    如果是以上的结果那么说明此项目是使用https协议进行访问的(如果地址是git开头则表示是git协议)

    可以登陆你的github,在上面可以看到你的ssh协议相应的url,类似:

     

    复制上述的ssh链接,然后使用命令 git remote set-url 来调整url。

    [root@kube-node1 game-of-life]# git remote set-url origin git@github.com:useyunwei/game-of-life.git
    [root@kube-node1 game-of-life]# git remote -v
    origin git@github.com:useyunwei/game-of-life.git (fetch)
    origin git@github.com:useyunwei/game-of-life.git (push)

    再次使用命令 git remote -v 查看一下,url是否已经变成了ssh地址。

    然后就可以愉快的使用git fetch, git pull , git push,不用再输入密码

      

  • 相关阅读:
    网络流强化-HDU 3338-上下界限制最大流
    OJ测试数据追溯方法
    网络流强化-HDU2732
    网络流强化-UVA10480
    网络流强化-HDU4280
    网络流强化-POJ2516
    POJ 3281 网络流 拆点保证本身只匹配一对食物和饮料
    动态规划-递推-HDU2048
    java List<Item> its=new ArrayList<Item>(); Map按value中的某字段排序
    Spring jar下载地址:
  • 原文地址:https://www.cnblogs.com/wyzhou/p/9835927.html
Copyright © 2011-2022 走看看