You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过SSH克隆自托管Git仓库报错的排查与解决

问题:通过SSH克隆自建Git仓库失败

我找到的大多数解决方案都是关于从GitHub或GitLab等第三方托管平台克隆仓库的,但我需要通过SSH克隆家里服务器上的Git仓库,却持续遇到报错。

相关背景

  • 可正常通过SSH访问目标目录
  • 已在test文件夹内初始化Git

SSH主机配置

Host my-server
  HostName my-server.domain.com
  Port 222

执行命令及输出

$ git clone my-server:mnt/path/directory/test/test.git
Cloning into 'test'...
username@my-server.domain.com's password: 

fatal: 'mnt/path/directory/test/test.git' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

$ git clone ssh://my-server:mnt/path/directory/test/test.git
Cloning into 'test'...
username@my-server.domain.com's password:
fatal: 'mnt/path/directory/test/test.git' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

$ git clone ssh://my-server:222/mnt/path/directory/test/test.git
Cloning into 'test'...
username@my-server.domain.com's 
fatal: 'mnt/path/directory/test/test.git' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.


$ pwd
/mnt/path/directory/test

$ ls -lah                                   
total 12K
drwxr-xr-x. 3 username username 4.0K Feb 27 17:03 .
drwxr-xr-x. 7 username username 4.0K Feb 27 17:03 ..
drwxr-xr-x. 8 username username 4.0K Feb 27 18:32 .git
-rw-r--r--. 1 username username    0 Feb 27 17:03 test.txt

解决方案

由于SSH端口不是默认端口,以下两种方法可解决问题:

方法一:指定用户名、域名和端口

$ git clone ssh://username@my-server.domain.com:222/mnt/path/directory/test
Cloning into 'test'...
username@my-server.domain.com's password: 
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.

方法二:在~/.ssh/config中配置用户名

$ cat ~/.ssh/config

Host my-server
  HostName my-server.domain.com
  User username
  Port 222

$ git clone my-server:/mnt/path/directory/test
Cloning into 'test'...
username@my-server.domain.com's password: 
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.

内容的提问来源于stack exchange,提问作者dreamzboy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 20:55:33