公司内网 git clone提示fatel失败

📅 2026/7/9 15:32:00 👁️ 阅读次数 📝 编程学习
公司内网 git clone提示fatel失败

按下面一步一步来就行,配完以后公司内网也能git clone


第一步:生成 SSH key

终端执行:

ssh-keygen -t ed25519 -C "你的GitHub邮箱"

例如:

ssh-keygen -t ed25519 -C "abc@gmail.com"

第二步:一路回车

会看到:

Enter file in which to save the key

直接回车。

然后:

Enter passphrase

你可以:

  • 直接回车(简单)

  • 或设置密码(更安全)

最终会生成:

~/.ssh/id_ed25519 ~/.ssh/id_ed25519.pub

第三步:启动 ssh-agent

执行:

eval "$(ssh-agent -s)"

然后添加 key:

ssh-add ~/.ssh/id_ed25519

第四步:查看公钥

执行:

cat ~/.ssh/id_ed25519.pub

会输出一长串:

ssh-ed25519 AAAAC3NzaC1...

全部复制。


第五步:添加到 GitHub

打开 GitHub:

Settings → SSH and GPG keys → New SSH key

Title 随便写:

Ubuntu Laptop

Key 粘贴刚才内容。

点击:

Add SSH key

第六步:配置 GitHub 走 443 端口(关键)

因为公司网络屏蔽普通 GitHub HTTPS。

创建配置:

mkdir -p ~/.ssh nano ~/.ssh/config

写入:

Host github.com HostName ssh.github.com User git Port 443

保存:

Ctrl + O 回车 Ctrl + X

第七步:设置权限

执行:

chmod 600 ~/.ssh/config chmod 700 ~/.ssh

第八步:测试 SSH

执行:

ssh -T git@github.com

第一次会问:

Are you sure you want to continue connecting

输入:

yes

成功结果

你会看到:

Hi xxx! You've successfully authenticated

说明:

✅ SSH 配置成功
✅ 公司网络可用
✅ GitHub 可访问


第九步:clone 测试

现在不要再用 HTTPS:

❌ 不要:

git clone https://github.com/xxx/xxx.git

改成:

✅ 用 SSH:

git clone git@github.com:octocat/Hello-World.git

以后都用 SSH

例如:

git clone git@github.com:你的用户名/项目.git

不会再碰 HTTPS TLS 问题。