首页 > 技术文章 > Windows GIT SSH 免密教程

pingyun 2019-09-01 22:10 原文

Windows GIT SSH 免密教程

  1. 安装git客户端,最新下载地址如下 https://github.com/git-for-windows/git/releases/download/v2.23.0.windows.1/Git-2.23.0-64-bit.exe

  2. 安装完毕后, 进入.ssh目录,笔者目录如下:
    C:\Users\Administrator.ssh,进入后,右键

    git bash here
    
  3. 新建ssh key

    ssh-keygen -t rsa -==C== "chonguo@126.com"
    键入 id_rsa_gitee
    按enter键直到结束,这时会发现生成两个私钥和公钥
    
  4. 将私钥加入到ssh agent

    ssh-add ~/.ssh/id_rsa_gitee
    

    如果出现 Could not open a connection to your authentication agent.
    则需要

    ssh-agent bash
    ssh-add ~/.ssh/id_rsa_gitee
    
  5. 在该目录下新建config文件

   
	 #该配置用于个人gitee 上  
    #Host 服务器别名  
    Host gitee.com
    #HostName 服务器ip地址或机器名  
    HostName gitee.com
    #User连接服务器的用户名  
    User chonguo@126.com
    #IdentityFile 密匙文件的具体路径  
    IdentityFile C:\Users\Administrator\.ssh\id_rsa_oschina
    
    #该配置用于个人 github 上  
    #Host 服务器别名  
    Host github.com
    #HostName 服务器ip地址或机器名  
    HostName github.com
    #User连接服务器的用户名  
    User chonguo@126.com
    #IdentityFile 密匙文件的具体路径  
    IdentityFile C:\Users\Administrator\.ssh\id_rsa_github

    #该配置用于aliyun code 上  
    #Host 服务器别名  
    Host code.aliyun.com
    RSAAuthentication yes
    #HostName 服务器ip地址或机器名  
    HostName code.aliyun.com
    #User连接服务器的用户名  
    User chonguo@163.com
    #IdentityFile 密匙文件的具体路径  
    IdentityFile C:\Users\Administrator\.ssh\id_rsa_aliyun
  1. 登录gitee或者github配置ssh keys,用notepad打开并复制id_rsa_gitee.pub中内容即可

推荐阅读