Linux 云服务器 Git 环境配置

1. 系统环境

  • Debian GNU/Linux 13 (trixie)

2. 创建新用户

请输入以下命令,依次填写所有用户信息。最后确认信息是否正确,输入 Y 并回车。

请更换 user_name 为实际的用户名~~~

1
sudo adduser user_name

如果希望这个新用户能够执行 sudo 命令来管理系统,需要将其加入 sudo 用户组:

1
sudo usermod -aG sudo user_name

创建完成后,可以通过以下命令切换到新用户进行测试:

1
su - user_name

3. 安装 Git

运行以下命令来安装 git 和 curl:

1
sudo apt update && sudo apt install -y git curl

4. 配置个人信息

使用以下命令配置 Git 用户名和邮箱:

1
2
git config --global user.name "username"
git config --global user.email "[email protected]"

使用以下命令查询配置:

1
2
3
4
5
6
# 项目配置
git config --list
# 系统配置
git config --system --list
# 个人配置
git config --global --list

5. 配置 SSH 密钥

5.1 生成密钥

如果希望每次使用密钥时都输入密码以增加安全性,可以输入一个密码。如果嫌麻烦,直接按回车跳过。

1
ssh-keygen -t ed25519 -C "[email protected]"

5.2 查看公钥

1
cat ~/.ssh/id_ed25519.pub

随后在 GitHub 中创建新的 SSH 密钥,并将公钥复制进去保存。

5.3 测试连通性

1
ssh -T [email protected]

6. 配置流量转发

6.1 SSH 流量转发

首先,我们需要安装流量转发工具 corkscrew,命令如下:

1
sudo apt install -y corkscrew

然后编辑文件 ~/.ssh/config,复制以下内容到文件中:

1
2
3
Host github.com
User git
ProxyCommand corkscrew 127.0.0.1 10808 %h %p

请修改 10808 端口为实际使用的代理端口。

corkscrew 是一个专门用于 HTTP / HTTPS 代理的工具。转发端口必须是 HTTP 代理端口或者为混合代理端口,不支持 SOCKS5 代理端口。

6.2 HTTP / HTTPS 流量转发

如果需要使用 Git 的 HTTPS 方式拉取仓库,则需要单独配置 Git 的代理。最直接的方法是为全局 Git 配置 http.proxy 和 https.proxy:

1
2
git config --global http.proxy http://127.0.0.1:10808
git config --global https.proxy http://127.0.0.1:10808

查看当前的代理配置:

1
git config --global --get-regexp 'http.*proxy'

如需取消代理配置,可执行:

1
2
git config --global --unset http.proxy
git config --global --unset https.proxy

请将 127.0.0.1:10808 替换为实际可用的代理地址和端口。

7. 配置代理服务

请参考以下文章:

通过 SSH 将本地代理反向隧道映射到云服务器 | Unrealfeathers’ Blog

全部配置完成后,请打开本地计算机的代理服务。开始享受高速 GitHub 仓库拉取叭!


Linux 云服务器 Git 环境配置
https://flowerdown.org/posts/20261012-202243
作者
Unrealfeathers
发布于
2026年10月12日
许可协议