Spaces:
Running
Running
A newer version of the Gradio SDK is available:
6.1.0
Git Push 到 Hugging Face 问题修复指南
问题描述
Connection closed by 198.18.0.7 port 22
fatal: Could not read from remote repository.
快速解决方案(推荐)
方案 1: 切换到 HTTPS(最简单,推荐)
查看当前远程仓库 URL:
git remote -v将 SSH URL 切换为 HTTPS URL:
# 格式:git remote set-url origin https://huggingface.co/spaces/USERNAME/SPACE_NAME # 例如: git remote set-url origin https://huggingface.co/spaces/your-username/your-space-name使用 Hugging Face token 进行认证:
- 访问 https://huggingface.co/settings/tokens
- 创建一个新的 token(需要有 write 权限)
- push 时使用 token 作为密码:
git push # Username: 你的 Hugging Face 用户名 # Password: 你的 token(不是密码)
方案 2: 修复 SSH 配置
如果必须使用 SSH,按以下步骤操作:
检查 SSH key 是否存在:
ls -la ~/.ssh/如果没有 SSH key,生成一个:
ssh-keygen -t ed25519 -C "[email protected]" # 按 Enter 使用默认路径查看公钥并添加到 Hugging Face:
cat ~/.ssh/id_ed25519.pub- 复制输出的内容
- 访问 https://huggingface.co/settings/keys
- 点击 "New SSH key",粘贴公钥并保存
创建或编辑 SSH 配置文件:
nano ~/.ssh/config添加以下内容:
Host hf.co HostName hf.co User git Port 22 IdentityFile ~/.ssh/id_ed25519 IdentitiesOnly yes设置正确的文件权限:
chmod 600 ~/.ssh/config chmod 600 ~/.ssh/id_ed25519 chmod 644 ~/.ssh/id_ed25519.pub测试 SSH 连接:
ssh -T [email protected]应该看到类似 "You've successfully authenticated" 的消息
方案 3: 使用 SSH over HTTPS 端口(如果端口 22 被防火墙阻止)
如果端口 22 被阻止,可以尝试使用端口 443:
编辑 SSH 配置:
nano ~/.ssh/config添加或修改为:
Host hf.co HostName hf.co User git Port 443 IdentityFile ~/.ssh/id_ed25519 IdentitiesOnly yes测试连接:
ssh -T [email protected]
诊断步骤
运行诊断脚本:
chmod +x fix_git_push.sh
./fix_git_push.sh
常见问题
Q: 如何找到我的 Hugging Face 空间名称?
A: 查看当前远程 URL:
git remote -v
或者访问 https://huggingface.co/spaces 查看你的空间列表
Q: 如何生成新的 SSH key?
A:
ssh-keygen -t ed25519 -C "[email protected]"
Q: 如何查看已添加的 SSH key?
A:
cat ~/.ssh/id_ed25519.pub
Q: HTTPS 方式需要每次都输入 token 吗?
A: 可以配置 Git credential helper 来保存凭据:
git config --global credential.helper store
推荐做法
对于大多数用户,使用 HTTPS + token 是最简单可靠的方式,因为:
- 不需要配置 SSH
- 不受防火墙端口限制
- 更容易调试
- Hugging Face 官方推荐