Forgejo, Gitea and Codeberg SSH: "Permission denied (publickey)"
The server closed the SSH login because no key that your client offered belongs to an account, or because the user name is not the one the server uses for Git. The words are the same in every case, so the message alone does not say which. On Codeberg the user is always git. On your own server, use the user shown in the clone URL on the repository page, and add the public key under SSH / GPG Keys in your settings.
The message, and what it does not tell you
With OpenSSH 10.2 (November 22, 2026), a key file that does not exist (against codeberg.org and code.forgejo.org) and a new key that is on no account (against codeberg.org) end the same way:
git@codeberg.org: Permission denied (publickey).
With the user forgejo instead of git on codeberg.org the line was the same, only the user name before the at sign changed. A Cloudron forum thread about Forgejo 14.0.3 with its built-in SSH server shows the same line, and the fix there was the user name: ssh -T cloudron@HOST -p 29418 worked where git@ did not (public report).
Pull requests in the IDE do not use SSH: Pull Request Inbox for Forgejo and Gitea, a plugin for JetBrains IDEs, keeps one token for Codeberg and one for your own server, each sent only to its own server, and on a 401 says that the server rejected it and shows the server's message.
Find out which case it is
Run the login test with verbose output (replace the host with your server, and add -p PORT if it does not use port 22):
ssh -vT git@codeberg.org
Authenticating to codeberg.org:22 as 'git'shows the user and port that SSH really used.no such identity: ...means the key file named in your config does not exist.- No
Offering public key:line means the client offered nothing: no key file at the default path, or none loaded. Codeberg's SSH key page shows the agent commandseval $(ssh-agent)andssh-add, and aHost codeberg.orgblock withUser gitandIdentityFilefor a key with another name. - An
Offering public key: ... SHA256:...line followed byPermission deniedmeans a key was offered and the server does not have it. That key is not in your account (or is in another account).
When it works, the same page says the answer begins with "Hi there, ...! You've successfully authenticated with the key named ..., but Forgejo does not provide shell access."
Fix each case
- Wrong user. Codeberg:
git@codeberg.org:USER/REPO.gitorssh://git@codeberg.org/USER/REPO.git, as Codeberg's page shows. Your own server: copy the SSH clone URL from the repository page. Forgejo shows there the user set bySSH_USER, which by default isBUILTIN_SSH_SERVER_USER(default: the user Forgejo runs as), and the port set bySSH_PORT, in the configuration cheat sheet. The cheat sheet says to leaveSSH_USERblank and changeBUILTIN_SSH_SERVER_USERin most cases. - Key not offered. Create one with
ssh-keygen -t ed25519 -a 100, as Codeberg's page does, and load it withssh-add, or name it in~/.ssh/config. - Key not on the account. Copy the public key (the
.pubfile, never the private one). In your settings, SSH / GPG Keys, Add key, a name, the key in the Content field, and Add key again (menu names from Codeberg's page;https://codeberg.org/user/settings).
If SSH asks "Are you sure you want to continue connecting" the first time, that is the host key check, not this error: compare it with the fingerprints Codeberg publishes.
Git over HTTPS instead of SSH needs an access token when 2FA is on: "fatal: Authentication failed".
Forgejo and Gitea pull requests in IntelliJ IDEA
Pull Request Inbox for Forgejo and Gitea, a plugin by Lesstep for JetBrains IDEs 2024.1 or later, keeps one token for Codeberg and one for your own server, each in the IDE's password safe and sent only to its own server. Without a token it reads public repositories; for a private one it says that it needs an access token. When the server refuses a token with 401, the plugin says that the server rejected it (expired or deleted, or from another server), shows the server's message, and offers to open its settings, which link to your server's token page. Reading is free; approving, commenting and merging are Pro (US$1.50 a month, with a 30-day trial).
Get it on JetBrains Marketplace
Forgejo, Gitea and Codeberg are names of their respective owners; IntelliJ IDEA is a trademark of JetBrains s.r.o. This page is not affiliated with or endorsed by the Forgejo project, Codeberg e.V., the Gitea project or JetBrains.
More: Git over HTTPS "fatal: Authentication failed" with 2FA · Git "self-signed certificate" on your own Forgejo or Gitea · 401 "token is required" and the unknown-token messages · "token does not have at least one of required scope(s)" · 404 "The target couldn't be found." and "not found" · Forgejo and Gitea pull request not created (409, 422, 403) · Forgejo and Gitea pull request plugins for IntelliJ IDEA, compared · 日本語