--- type: Guide purpose: Finish the Gitea install wizard, 2FA, SSH keys and tokens. answers: - "How is Gitea configured after the stack is up?" cites: - compose.yml --- # 07 — Gitea Setup Initial Gitea configuration via install wizard, admin hardening, 2FA, and SSH key registration. ## Prerequisites - The stack is up on the server (from [06-docker-deploy.md](06-docker-deploy.md)) **Run this step before the port-forwards exist, not after.** Gitea's first-run wizard hands ownership of the instance to whoever loads it first. Until the admin account is created, a publicly reachable Gitea is a giveaway. The whole of this doc works over an SSH tunnel with no forward in place, so there is no reason to expose it first. Gitea binds `127.0.0.1:3000` on the server — unreachable even from the LAN. Reach it from the dev machine with a tunnel: ```bash ssh -N -L 3000:127.0.0.1:3000 -p 2234 admin@192.168.1.50 ``` Leave that running in its own terminal; `http://localhost:3000` is then Gitea. Everything below happens there. Close the tunnel when done. ## 1. Install wizard Visit `http://localhost:3000` — first visit shows the install wizard. The redirect after **Install Gitea** goes to `https://git.example.com` and hangs, because `ROOT_URL` says so and no forward exists yet. Expected. Go back to `http://localhost:3000`; the install completed and you are logged in. **Database settings** (already set via environment, verify): - Database type: SQLite3 - Path: `/data/gitea/gitea.db` **General settings:** | Field | Value | |---|---| | Site title | your site name | | Repository root path | `/data/git/repositories` | | Git hooks path | `/data/gitea/git-repositories` | | Log path | `/data/gitea/log` | | Server domain | `git.example.com` | | Gitea base URL | `https://git.example.com/` | | SSH server port | `2222` | **Admin account** — expand *Administrator Account Settings* at the bottom and fill it in during the wizard. Skipping it leaves the instance ownerless, and the first account to register takes it. | Field | Value | |---|---| | Admin username | choose a username (not "admin" or "root") | | Admin password | strong password (20+ chars, use a password manager) | | Admin email | your email | Click **Install Gitea**. A user and an organization share one namespace in Gitea — an org is an account type, not a separate thing. So the admin username also rules out that name for any future org. Settle on the handle now: renaming later works and Gitea keeps a redirect, but every clone URL already in a `.git/config` somewhere still points at the old one. Verify what the wizard actually wrote: ```bash docker exec -u git gitea gitea admin user list ``` Expect one row, `IsAdmin true`. ## 2. Confirm public registration is disabled `compose.yml` already sets `GITEA__service__DISABLE_REGISTRATION=true`, and the wizard writes it into `app.ini`. Confirm rather than re-apply: ```bash docker exec gitea grep DISABLE_REGISTRATION /data/gitea/conf/app.ini ``` Expect `DISABLE_REGISTRATION = true`. If it says otherwise, the env var is not reaching the container — fix it there, not in `app.ini`, or the next `docker compose up` overwrites your edit. Note that `app.ini` also holds generated secrets (`*_JWT_SECRET`, `SECRET_KEY`). Do not paste the file, or that section of it, anywhere. Delete a secret line and restart the container to have Gitea regenerate it. ## 3. Enable 2FA for admin account Log in as admin → User settings (top-right avatar) → Security → Two-Factor Authentication → Enroll. Scan QR code with TOTP app (Aegis, Google Authenticator, etc.). Save backup codes in a password manager. ## 4. Register your SSH public key for git operations User settings → SSH / GPG Keys → Add Key. Paste your public key (`~/.ssh/id_ed25519.pub`): ```bash # on your local machine cat ~/.ssh/id_ed25519.pub ``` Confirm it registered: ```bash docker exec gitea sqlite3 /data/gitea/gitea.db \ "select name,fingerprint from public_key;" ``` ## 5. Test git over SSH Gitea's SSH listener is bound to `0.0.0.0:2222`, so this works over the LAN before any port-forward exists — use the server's LAN IP now, the hostname after [09](09-fail2ban.md): ```bash ssh -T git@192.168.1.50 -p 2222 # LAN, works today ssh -T git@git.example.com -p 2222 # public, after 09 # expected: Hi there, ! You've successfully authenticated with the key # named , but Gitea does not provide shell access. ``` ## 6. Test git over HTTPS Needs the public hostname, so this one waits for [09](09-fail2ban.md). The rest of this doc does not. Create a Personal Access Token (PAT) for HTTPS push: User settings → Applications → Generate Token. Select scopes: `repo`. Copy token. A PAT is not a convenience here — with 2FA enrolled (step 3), your account password no longer authenticates git over HTTPS at all. The PAT is the only HTTPS credential. Treat it like a password: password manager, never a repo, never a shell command. ```bash git clone https://git.example.com//test-public.git cd test-public echo "hello" > test.txt git add test.txt && git commit -m "test" git push # username: your Gitea user; password: the PAT ``` For convenience, configure git credential cache: ```bash git config --global credential.helper cache ``` **For day-to-day pushes use SSH, not HTTPS.** A push over an HTTPS remote has to prompt for the PAT, so any non-interactive push (an agent, a script, jj without a credential helper) fails with: ``` fatal: could not read Username for 'https://git.example.com': No such device or address ``` The SSH key from step 4 needs no token. Switch an existing clone once: ```bash git remote set-url origin ssh://git@git.example.com:2222//.git # git jj git remote set-url origin ssh://git@git.example.com:2222//.git # jj ssh -T -p 2222 git@git.example.com # "Hi there, ! …" ``` The explicit `ssh://…:2222/` form is required — the scp-style `git@host:repo` shorthand cannot carry a port. ## 7. Create a test repository Gitea UI → **+** → New Repository. Create one public (`test-public`) and one private (`test-private`). Both work over the tunnel, before any forward exists. Verify anonymously — the tunnel carries no session, so plain `curl` is already a logged-out client: ```bash curl -s -o /dev/null -w "%{http_code}\n" http://localhost:3000//test-public curl -s -o /dev/null -w "%{http_code}\n" http://localhost:3000//test-private ``` Expect `200` then `404`. Gitea returns 404 rather than 403 for private repos on purpose — a 403 would confirm the repo exists. Delete both when done, or keep `test-public` as a scratch target. ## Checklist - [ ] Wizard run over the SSH tunnel, before any port-forward exists - [ ] Gitea install wizard completed, admin account created in the wizard itself - [ ] Public registration disabled (confirmed in `app.ini`) - [ ] Admin 2FA enabled, backup codes saved - [ ] SSH public key registered in Gitea - [ ] `ssh -T` test passes (LAN IP now, hostname after 09) - [ ] HTTPS push test passes (after 09) - [ ] Public repo visible without login - [ ] Private repo returns 404 without login ## Next step Continue with [08-firewall.md](08-firewall.md).