Skip to content

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.

ssh-keygen -t ed25519 -C "gitea-deploy-readonly" -f ~/keys/gitea_deploy_readonly -N ""
chmod 600 ~/keys/gitea_deploy_readonly
chmod 644 ~/keys/gitea_deploy_readonly.pub
cat ~/keys/gitea_deploy_readonly.pub

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:

GIT_SSH_COMMAND="ssh -i ~/keys/gitea_deploy_readonly" git pull origin main

Expected result — fetch succeeds without errors, commits appear locally.

Try push with the same key:

GIT_SSH_COMMAND="ssh -i ~/keys/gitea_deploy_readonly" git push origin main

Expected result — the remote rejects the write. Typical error:

remote: Permission denied (publickey).
fatal: unable to access 'https://.../': The remote end hung up unexpectedly

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:

CheckCommand / Fix
Key permissionschmod 600 ~/keys/gitea_deploy_readonly
SSH agent loaded`ssh-add -L
SELinux / AppArmorrestorecon -R ~/.ssh/ or check audit2allow per logs
Deploy key scopeOpen Settings → Deploy keys in Gitea, verify key is bound to the correct repo
“Read only” flagGo back to settings, the flag must be enabled
Known hosts mismatchssh-keyscan gitea.example.com >> ~/.ssh/known_hosts
SSH daemon configCheck 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.