在Windows环境下设置SSH克隆GitHub仓库的步骤如下:
1. 生成SSH密钥
- 打开 Git Bash(如果你已经安装了Git)。
- 输入以下命令生成SSH密钥:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
- 按 Enter 键接受默认文件名(通常是
C:\Users\你的用户名\.ssh\id_rsa
),然后可以选择输入一个密码(可选)。
2. 启动SSH代理
在Git Bash中,启动SSH代理:
eval "$(ssh-agent -s)"
3. 添加SSH密钥到SSH代理
使用以下命令将私钥添加到SSH代理:
ssh-add ~/.ssh/id_rsa
4. 将SSH公钥添加到GitHub
-
打开公钥文件:
cat ~/.ssh/id_rsa.pub
或者在文件浏览器中打开
C:\Users\你的用户名\.ssh\id_rsa.pub
,然后复制内容。 -
登录你的GitHub账号,进入 Settings > SSH and GPG keys > New SSH key,粘贴你复制的公钥,然后保存。
5. 使用SSH URL克隆仓库
在Git Bash中运行以下命令克隆仓库:
git clone git@github.com:asudhak/peachfuzz-code.git
6. 验证SSH连接
你可以通过以下命令检查SSH连接是否成功:
ssh -T git@github.com
如果连接成功,你会看到类似“Hi username! You've successfully authenticated, but GitHub does not provide shell access.”的信息。
按照这些步骤,你应该能够在Windows环境下成功使用SSH克隆GitHub仓库。
fuyul@mine MINGW64 /d/edgeDownload/resource/test
$ ssh-keygen -t rsa -b 4096 -C "fuyulai2024@163.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/fuyul/.ssh/id_rsa):
/c/Users/fuyul/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/fuyul/.ssh/id_rsa
Your public key has been saved in /c/Users/fuyul/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:S60u0VaP09C4ySgFp5Uv/fSNpCu788SfPtV/sZ95Cts fuyulai2024@163.com
The key's randomart image is:
+---[RSA 4096]----+
| . |
| . + |
| = o o |
| . o.* o . |
| oS=.X + o.|
| o.+o*.= o.+|
| +o .+. .+|
| .. o..=.o*|
| .. o*o.E==|
+----[SHA256]-----+
fuyul@mine MINGW64 /d/edgeDownload/resource/test
$ eval "$(ssh-agent -s)"
Agent pid 182
fuyul@mine MINGW64 /d/edgeDownload/resource/test
$ ssh-add ~/.ssh/id_rsa
Identity added: /c/Users/fuyul/.ssh/id_rsa (fuyulai2024@163.com)
fuyul@mine MINGW64 /d/edgeDownload/resource/test
$ cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3Nz......省略2ZXhyi29vRN7lk2Dy8lQp3bK/6F/qlyeAGS2eqXFsUo+bp3sQ2kooOXem22OXxjRsMlr7d3hpaRJOwfo1ByFlTOwo7Q== fuyulai2024@163.com
fuyul@mine MINGW64 /d/edgeDownload/resource/test
$