文章目录
SSH in Git Bash & Tortoise Git
有的同学使用Git生成了SSH密钥发现无法使用TortoiseGit进行SSH协议的连接,这里面其实有点不太一样。
SSH in Git Bash
1.Generate SSH Key
Two ways.
-
Use command line in GitBash
- 在任意窗口右键打开GitBash
- 输入命令行生成SSH密钥
ssh-keygen -t rsa -C "your email" -b 4096
- 在任意窗口右键打开GitBash
-
Use Git GUI
- 在任意窗口右键打开Git GUI
- Click Help -> Generate SSH Key or Show SSH Key
Where are keys?
# 百分号内容表示你的用户文件夹
%User Directory%/.ssh/
In this directory, you can see at least two files:
- id_rsa: private SSH key
- id_rsa.pub: public SSH key, you need to add this to your GitHub/GitLab
2.Using SSH in Git Bash/GUI
- 将上一步的id_rsa.pub文件中的内容配置到你GitHub/GitLab
-
在本地使用Git Bash, 这里我给了简单的例子
-
克隆远程仓库到本地(SSH协议)
git clone [git@开头的ssh链接]
-
进入本地仓库项目, 此时的目录都可叫做工作空间(working directory)
cd [Project Name]
-
[可选]创建一个文件
touch README.md
-
将文件添加到暂存区(staging area)
git add README.md
-
将暂存区文件提交到本地仓库(local repository)
git commit -m "这里是注释,必填"
-
将本地仓库的变更提交到远程仓库(remote repository)
git push -u origin master
-
SSH in Tortoise Git
You need to install the Tortoise first.
1.Generate SSH Key
Find PuTTYgen Client in your system, it has been installed with Tortoise Git.
- System Start -> Search “Puttygen” -> Click to Run
Then, Click Generate, wait for a moment.
- You can set your E-mail in Key comment
- You can set password in Key passphrase
After generated, save public key & private key.
2.Using SSH in Tortoise Git
- 将上一步生成的公钥配置到你GitHub/GitLab中,可参考前文。
- 使用实例,这里以Clone一个Git仓库为例
- 右键打开Git Clone…
- 键入Git链接
- 勾选Load Putty Key, 选择前面生成的私钥
- OK
3. Tortoise Git图形化界面的具体使用就不举例了