Git 使用密钥对

生成SSH key

  1. 打开 Git Bashgit

  2. 输入您的邮箱地址ssh

    ssh-keygen -t rsa -b 4096 -C "<em>your_email@example.com</em>"
  3. 生成密钥对工具

    • 直接输入Enter便可命令行

    Generating public/private rsa key pair.
  4. 输入保存密钥对的文件地址code

    • 默认使用 /c/Users/you/.sshit

    • 生成id_rsa以及id_rsa.pub两个文件io

    • 直接输入Enter便可email

    Enter a file in which to save the key (/Users/<em>you</em>/.ssh/id_rsa): <em>[Press enter]
  5. 输入密钥对密码file

    • 若是输入密码则在每次启动Pageant时,需输入一次密码。若当前工做电脑需多人共用,建议加入密码,并在每次操做完毕后关闭Pageant.rsa

    Enter passphrase (empty for no passphrase): <em>[Type a passphrase]
    Enter same passphrase again: <em>[Type passphrase again]

使用密钥对

添加公钥

  1. 使用记事本打开生成的两个文件中后缀为 .pub 的文件

  2. 复制其中全部内容

  3. 将内容黏贴至您的我的信息中

    • 以 code.aliyun.com 为例

    • Home -> Profile -> sshKeys -> 右上角 ADD SSH KEY (不理解为啥 code 部分都是英文)

添加私钥

使用命令行模式

  1. 打开 Git Bash

  2. Clone您的项目

    • 打开您的项目页面,选择SSH方式,拷贝项目路径

    • 项目路径应以 git@ 开头,以 https 开头的链接不在本文讨论范围内

    • 其余命令查询请输入 git help

    git clone <em>your_project_path

使用 TortoiseGit

添加私钥

TortoiseGit 以及 SourceTree 等工具仅支持 ppk 格式私钥文件

  1. 打开 Puttygen -> Conversions -> Import key -> 选择已生成的 id_rsa 文件 -> Save private key
    ->输入欲生成文件名

  2. 打开Pagent -> Add Key -> 选择以生成的 ppk 文件 -> 完成后在窗口中添加一条新信息

拉取项目
  1. 获取项目路径

    • 打开您的项目页面,选择SSH方式,拷贝项目路径

    • 项目路径应以 git@ 开头,以 https 开头的链接不在本文讨论范围内

  2. Clone您的项目

相关文章
相关标签/搜索