背景

  • 默认Gitea是以容器的形式运行的,并默认不使用Gitea内部的ssh服务而是使用转发宿主机ssh端口的方式,一般会将222端口绑定到容器的22端口上。

问题

安装完并新建仓库后,无法使用 git clone git@host:user/repo.git 的方式拉取仓库。

http方式一般不会出问题。

原因

  • 由于公开出来的端口不是默认的22而是222所以需要配置客户端的.ssh/config 文件,配置以下内容
Host your-gitea-host
  HostName your-gitea-host
  User git
  # 这里我使用了非常用的key,这不是必须的
  IdentityFile /c/Users/tuoxi/.ssh/id_ecdsa_gitea
  IdentitiesOnly yes
  # 主要是这里一定要设置为222
  Port 222
  • 在gitea的个人设置中添加你的公钥。注意,正确的添加位置如下。添加到每一个仓库设置里的key是没用的,另外下图画圈右侧的“密钥”那个也是不对的,那些都是用来做其他用途的。(Action)

测试

上述设置了以后应该就可以用ssh拉取仓库了,比如

要注意的是host名(your-gitea-host处)需要和config中设置的一致才会使用config的222端口的设置,所以如果不是真实的域名而是修改hosts来映射的局域网的“假”域名或主机名,也要保证两边一致。

$ git clone git@your-gitea-host:mango/test.git
Cloning into 'test'...
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), 218 bytes | 218.00 KiB/s, done.
Last modification:May 29, 2023
If you think my article is useful to you, please feel free to appreciate