生成 ssh 秘钥对记录在windows、linux、macOS下配置Git,及给Git配置代理的详细步骤。
# 生成 ssh 秘钥对,一路回车 $ ssh-keygen -t rsa # 查看公钥 $ cat ~/.ssh/id_rsa.pub配置用户名 邮箱
# 设置用户名 $ git config --global user.name "your name" # 设置密码 $ git config --global user.email "your email"
Windows 代理设置以上配置三种系统都是一样的。
1.安装git找到安装目录下的ssh_config文件
x64 C:Program FilesGitetcssh
x86 C:Program Files(x86)Gitetcssh
2.添加配置如下
Host ServerIP
IdentityFile “~/.ssh/id_rsa”
ProxyCommand /mingw64/bin/connect.exe -H ProxyIP:ProxyPort %h %p
MacOS Linux 设置代理如果是x86的版本需要修改mingw64为mingw32
- 安装 connect
# 下载 connect 源码 $ git clone https://github.com/moonagic/connect.git # 编译 connect 源码 $ cd connect && make # 将编译后的 connect 二进制文件拷贝到 bin 目录 $ cp connect /usr/local/bin
- 修改 ~/.ssh/config 如下
# ServerIP Git服务器IP # ProxyIP:ProxyPort 代理服务器IP与Port Host ServerIP IdentityFile "~/.ssh/id_rsa" ProxyCommand connect -H ProxyIP:ProxyPort %h %p



