zno2

Git & TortoiseGit

http://www.git-scm.com/download/

http://download.tortoisegit.org/

https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/

指南

1. Getting Started
2. Git Basics
3. Git Branching
4. Git on the Server
5. Distributed Git
6. GitHub
7. Git Tools
8. Customizing Git
9. Git and Other Systems
10. Git Internals

 

如何使用github

 1) 通过Git Bash 生成公钥、私钥(RSA非对称加密算法)

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

 

$ ssh-keygen ?
Too many arguments.
usage: ssh-keygen [-q] [-b bits] [-t dsa | ecdsa | ed25519 | rsa]
                  [-N new_passphrase] [-C comment] [-f output_keyfile]
       ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]
       ssh-keygen -i [-m key_format] [-f input_keyfile]
       ssh-keygen -e [-m key_format] [-f input_keyfile]
       ssh-keygen -y [-f input_keyfile]
       ssh-keygen -c [-P passphrase] [-C comment] [-f keyfile]
       ssh-keygen -l [-v] [-E fingerprint_hash] [-f input_keyfile]
       ssh-keygen -B [-f input_keyfile]
       ssh-keygen -D pkcs11
       ssh-keygen -F hostname [-f known_hosts_file] [-l]
       ssh-keygen -H [-f known_hosts_file]
       ssh-keygen -R hostname [-f known_hosts_file]
       ssh-keygen -r hostname [-f input_keyfile] [-g]
       ssh-keygen -G output_file [-v] [-b bits] [-M memory] [-S start_point]
       ssh-keygen -T output_file -f input_file [-v] [-a rounds] [-J num_lines]
                  [-j start_line] [-K checkpt] [-W generator]
       ssh-keygen -s ca_key -I certificate_identity [-h] [-n principals]
                  [-O option] [-V validity_interval] [-z serial_number] file ...
       ssh-keygen -L [-f input_keyfile]
       ssh-keygen -A
       ssh-keygen -k -f krl_file [-u] [-s ca_public] [-z version_number]
                  file ...
       ssh-keygen -Q -f krl_file file ...
ssh-keygen 使用帮助

Secure Shell key generator 工具,-t 指定加密算法类型(type),-b 指定密钥位数(bit) ,-C 注释(comment)

2)启动 ssh-agent 

eval $(ssh-agent -s)

 

单独执行 ssh-agent -s 会得到命令行,然后再通过eval 执行这些命令行才能真正启动 ssh-agent,有点类似 js里的eval

3) 将私钥添加到 ssh-agent

ssh-add ~/.ssh/id_rsa

如果提示 Could not open a connection to your authentication agent.   说明ssh-agent没有成功启动

4)将公钥 (id_rsa.pub) 添加到 github 

Settings -> SSH AND GPG keys -> New SSH key

5)使用 ssh 地址进行clone等操作

git clone git@github.com:witaste/ztest.git

 

补充:常用工具类所在目录结构

│  git-bash.exe
│  git-cmd.exe
│      
├─cmd
│      start-ssh-agent.cmd
│      start-ssh-pageant.cmd
│                  
└─usr
    ├─bin
    │  │  ssh-add.exe
    │  │  ssh-agent.exe
    │  │  ssh-keygen.exe
    │  │  ssh-pageant.exe    

 

 

使用优化

因为每次启动 git-bash ,都需要启动一个新的 ssh-agent ,而且旧的不能用 ,能不能实现自动化呢,就是每次打开 Git Bash 就会自动打开ssh-agent并且自动将私钥添加到ssh-agent,答案是有

第一种方案:

通过 GitHub Desktop 自带的 Git Shell 可自动完成

第二种方案:

添加自动化脚本

在当前用户目录(~)下创建 .profile 文件,内容是

env=~/.ssh/agent.env

agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }

agent_start () {
    (umask 077; ssh-agent >| "$env")
    . "$env" >| /dev/null ; }

agent_load_env

# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)

if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
    agent_start
    ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
    ssh-add
fi

unset env

第三种方案:

安装TortoiseGit 通过Pageant 软件加载PuTTY 形式的私钥

D:\Program Files\TortoiseGit\bin\puttygen.exe

1)生成 .ppk (可以通过PuTTYgen 生成新的密钥对,也可以load原有的私钥,转换成ppk)

2) 通过 Pageant 工具加载 ppk 

 

补充:tortoiseGit 目录结构

│  
├─bin
│      pageant.exe
│      puttygen.exe

 

posted on 2016-08-05 18:12  zno2  阅读(196)  评论(0编辑  收藏  举报

导航