Gitea read-only deploy key setup
Deploy keys in Gitea are handy when an external service or script needs read access to a repo without write permission. Unlike tokens or user accounts, deploy keys are repo-specific and managed via SSH. If the “Read only” box is checked, git pull works but push returns an error. This note covers generating the key, configuring it in Gitea, and common causes of Permission denied.
Preparation of repository and SSH key
First, generate a dedicated key for this repo. We’ll use ed25519 by default for modern systems, leave passphrase empty for automation, but strictly limit file permissions.
Store the key in a separate folder and don’t use it in a global ssh-agent, otherwise it may pick up for other repos. For scripts, better set GIT_SSH_COMMAND explicitly.
Copy the cat output — that exact string is what Gitea needs.
Setting up key in Gitea
Go to repo settings: Settings → Deploy keys → Add key. Paste the public key into the “Key” field. Below, enable the Read only toggle. Save.
If the “Read only” box is not checked, the deploy key grants full access, including push. Always verify the flag state before saving.
After saving, the key appears in the list with a lock icon and “Read only” text. It’s now bound to this repo and won’t work on others, even if the key is identical.
Checking access (git pull/push)
On the server or workstation, configure git to use this key. Example with environment variable:
Expected result — fetch succeeds without errors, commits appear locally.
Try push with the same key:
Expected result — the remote rejects the write. Typical error:
Deploy keys are repository‑scoped. They don’t affect the global SSH user profile and don’t give access to other Gitea repos.
Fixing typical failure: Permission denied
If pull fails and push hits Permission denied, run through the checklist. Here’s a diagnostic table:
| Check | Command / Fix |
|---|---|
| Key permissions | chmod 600 ~/keys/gitea_deploy_readonly |
| SSH agent loaded | `ssh-add -L |
| SELinux / AppArmor | restorecon -R ~/.ssh/ or check audit2allow per logs |
| Deploy key scope | Open Settings → Deploy keys in Gitea, verify key is bound to the correct repo |
| “Read only” flag | Go back to settings, the flag must be enabled |
| Known hosts mismatch | ssh-keyscan gitea.example.com >> ~/.ssh/known_hosts |
| SSH daemon config | Check PubkeyAuthentication yes and AuthorizedKeysFile .ssh/authorized_keys in /etc/ssh/sshd_config |
Typical failure scenario: key generated, added to Gitea, “Read only” checked, but git pull yields Permission denied. Most often the cause is file permissions above 600, or the SSH daemon doesn’t see the public key in ~/.ssh/authorized_keys (Gitea deploy keys write to ~/.ssh/authorized_keys under the git user, but only if GITEA_SSH path is configured). Another common case — the key was used in another repo with a push, imposing constraints.
Tweaks in custom/conf/app.ini Gitea (SSH_DOMAIN, SSH_PORT) can affect the connection address. Ensure ssh -T git@gitea.example.com returns the Gitea welcome, not an auth error.
That covers the practical aspects of setting up a read‑only deploy key in Gitea. The key can be reused for other repos by adding it again with the same “Read only” flag, but remember: each key instance is a separate access point to a specific repo.