微服托管代码?我选择Gitea!

Square

发布于652天前
生于忧患,咸鱼安乐
作为开发者,你肯定用过Github、Gitee之类的平台。可是有些场景下,自行部署一个代码托管平台更方便。下面,我将介绍如何使用gitea。

https://appstore.lazycat.cloud/#/shop/detail/cloud.lazycat.app.gitea

## 1. 安装

首先,去商店搜索Gitea,找到那个绿色的茶杯,点击安装,等待完成

![appstore.square.heiyu.space_(1080).jpg](https://dl.playground.lazycat.cloud/guidelines/23/07a076a2-1c6c-4edd-9688-d1f362651a48.jpg "appstore.square.heiyu.space_(1080).jpg")

## 2. 初始配置

安装完成后打开Gitea,进入首页,如果不习惯默认语言,可以在右下角修改显示语言:

![gitea.square.heiyu.space_(1080) (1).jpg](https://dl.playground.lazycat.cloud/guidelines/23/a6fdd02d-cce6-44a2-98a0-fbc8ea9d797e.jpg "gitea.square.heiyu.space_(1080) (1).jpg")

这时候Gitea还没有任何账户,第一个注册的用户将成为整个Gitea管理员账户。所以管理员安装完后请尽快注册,点击右上角开始注册。

![gitea.square.heiyu.space_(1080) (2).jpg](https://dl.playground.lazycat.cloud/guidelines/23/5fdef41b-cafd-4566-b210-48486facf6cb.jpg "gitea.square.heiyu.space_(1080) (2).jpg")

注册时需要填写邮箱。但是因为此时的gitea并没有配置任何邮箱服务,无法验证邮箱,所以在管理员配置邮箱服务前,邮箱不需要填写真实邮箱,填写一个格式正确的邮箱地址即可。填好注册信息后点注册帐号即可完成注册。

![gitea.square.heiyu.space_user_sign_up(1080) (1).png](https://dl.playground.lazycat.cloud/guidelines/23/52c2290b-43dc-449d-95c6-2c9a1c602482.png "gitea.square.heiyu.space_user_sign_up(1080) (1).png")

作为管理员账户,可以看到管理后台,对整个网站进行配置,比如删除帐号。也可以对其他人员赋予管理员权限,让他们也能管理网站。

![gitea.square.heiyu.space_admin_users(1080).jpg](https://dl.playground.lazycat.cloud/guidelines/23/1aab4dde-2e66-4b97-8828-aaf116e43d65.jpg "gitea.square.heiyu.space_admin_users(1080).jpg")

## 3. 创建仓库

无论是否是管理员,默认情况都能创建自己的仓库,点击右上角的加号,选择创建仓库。

![gitea.square.heiyu.space_(1080) (3).jpg](https://dl.playground.lazycat.cloud/guidelines/23/9237184b-dee4-4e45-9b74-a4fefffa572c.jpg "gitea.square.heiyu.space_(1080) (3).jpg")

填好表单后点击底部**创建仓库**即可

![gitea.square.heiyu.space_repo_create(1080) (1).png](https://dl.playground.lazycat.cloud/guidelines/23/a854688b-0615-437c-adb1-ac4af8ce95af.png "gitea.square.heiyu.space_repo_create(1080) (1).png")

## 4. 配置Git认证

到这里,一个部署在懒猫微服的代码仓库就已经创建好了,你可以放心地把代码push到这里,或者按照网页提示,初始化这个仓库。

![gitea.square.heiyu.space_demo_user_hello_world(1080).png](https://dl.playground.lazycat.cloud/guidelines/23/03b7be13-7b76-4bab-9449-fa8733744847.png "gitea.square.heiyu.space_demo_user_hello_world(1080).png")

但是,push的时候,你可能会发现,如果选ssh,会出现报错:

```bash
ssh: connect to host gitea.square.heiyu.space port 22: Connection refused
fatal: Could not read from remote repository.

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

选https,则需要输入用户名和密码,十分麻烦。

这里就需要再进行一点配置了,下面将分别介绍ssh和https的免密如何配置,根据你的链接选择一项来配置就行

### 配置SSH免密

首先,点击右上角的头像,选择设置:

![gitea.square.heiyu.space_(1080) (4).jpg](https://dl.playground.lazycat.cloud/guidelines/23/63e76501-e22d-456d-81d0-e573db9a5733.jpg "gitea.square.heiyu.space_(1080) (4).jpg")

然后,选择左侧菜单的SSH/GPG密钥,选择右边的导入密钥。

![gitea.square.heiyu.space_user_settings_keys(1080).jpg](https://dl.playground.lazycat.cloud/guidelines/23/8da8ea57-c5e9-4f4c-9766-bdd8927f361a.jpg "gitea.square.heiyu.space_user_settings_keys(1080).jpg")

将自己电脑的主目录(或者叫家目录,home目录)下的.ssh/id_ed25519.pub(有的电脑是id_rsa.pub)的内容拷贝到密钥内容的输入框中。密钥名称如果没有自动补全,或者想修改,可以自行填写,取一个名称。

![gitea.square.heiyu.space_user_settings_keys(1080) (1).jpg](https://dl.playground.lazycat.cloud/guidelines/23/8051998f-fcff-46f5-9871-bd492c42cc09.jpg "gitea.square.heiyu.space_user_settings_keys(1080) (1).jpg")

填好后选增加密钥,就完成添加啦。

*如果电脑中没有.ssh/xxx.pub文件,那么可以使用`ssh-keygen`命令创建一个。*

### 配置HTTPS免密

首先,点击右上角的头像,选择设置。然后,选择左侧菜单的应用。填入令牌名称,并在底下选择权限中把需要的权限改成读写(不确定的话都改成读写,问题不大)。最后点生成令牌

![gitea.square.heiyu.space_user_settings_applications(1080) (2).jpg](https://dl.playground.lazycat.cloud/guidelines/23/eaeacea4-5014-48b2-b442-e22960900533.jpg "gitea.square.heiyu.space_user_settings_applications(1080) (2).jpg")

点击按钮后网页上方会显示这次生成的`Access Token`(或者叫令牌),请及时复制下来,这个只显示一次。

将自己电脑的主目录(或者叫家目录,home目录)下的`.netrc`文件(如果没有就创建一下)添加一行设置,即可实现https认证也不需要密码。

```bash
machine gitea在微服中的域名 login 你的用户名 password 刚刚生成的令牌
```

其中微服中的域名,其实就是仓库地址的域名:

![gitea.square.heiyu.space_demo_user_hello_world(1080) (1).jpg](https://dl.playground.lazycat.cloud/guidelines/23/aa2cf658-cd29-48e0-9f81-d2b303a4014f.jpg "gitea.square.heiyu.space_demo_user_hello_world(1080) (1).jpg")

比如我的.netrc就是这样的

![Screenshot from 2024-08-20 19-55-43.jpg](https://dl.playground.lazycat.cloud/guidelines/23/dfc39b73-f6c2-4bb6-8e27-e60ee3348503.jpg "Screenshot from 2024-08-20 19-55-43.jpg")

## 结束

到这里就配置完成了。Enjoy Coding!

## 注意

**Gitea搭建在懒猫微服上,需要开启懒猫微服客户端方可使用**

如果在`git clone`这类操作中,出现`Could not connect to server`或者`无法连接到服务器`之类的报错,可以先检查一下懒猫微服客户端是否开启。

评论

3
Vim418天前

爱用

Vim418天前

好用

Bin651天前

沙发,我来尝尝鲜

说点什么呢~
收藏
4
3
0