"Permission denied (publickey)" when running in docker #2701

Closed
opened 2025-11-02 04:44:57 -06:00 by GiteaMirror · 2 comments
Owner

Originally created by @MoshiBin on GitHub (Jan 2, 2019).

  • Gitea version (or commit ref): f5be13e
  • Git version: Doesn't matter
  • Operating system: Any
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:

Description

After setting up gitea on Docker using a user called "gitea", creating a user and adding its public key, cloning fails with the Permission denied (publickey) error.

I looked into this and found something strange - in /etc/ssh/sshd_config, the AllowedUsers directive showed giteaea instead of gitea. In fact, every time I restarted the container, the user gained another "ea" at the end - so it went to giteaeaea etc. Changing the directive back to gitea manually doesn't help, because during startup it changes to giteaea.

My workaround: I copied /etc/ssh/sshd_config from the container to the host, and bound it into the container, setting the :ro flag so it would be immutable.

Originally created by @MoshiBin on GitHub (Jan 2, 2019). - Gitea version (or commit ref): f5be13e - Git version: Doesn't matter - Operating system: Any - Database (use `[x]`): - [ ] PostgreSQL - [ ] MySQL - [ ] MSSQL - [x] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [x] Not relevant - Log gist: ## Description After setting up gitea on Docker using a user called "gitea", creating a user and adding its public key, cloning fails with the `Permission denied (publickey)` error. I looked into this and found something strange - in `/etc/ssh/sshd_config`, the `AllowedUsers` directive showed `giteaea` instead of `gitea`. In fact, every time I restarted the container, the user gained another "ea" at the end - so it went to `giteaeaea` etc. Changing the directive back to `gitea` manually doesn't help, because during startup it changes to `giteaea`. My workaround: I copied `/etc/ssh/sshd_config` from the container to the host, and bound it into the container, setting the `:ro` flag so it would be immutable.
GiteaMirror added the type/bug label 2025-11-02 04:44:57 -06:00
Author
Owner

@techknowlogick commented on GitHub (Jan 2, 2019):

Did you pass the USER environment variable to the container?

If yes, then it is likely because of this line: 801843b011/docker/usr/bin/entrypoint (L7) It seems the regex should grep for AllowUsers git on a line, instead of search for that string where it could be the middle.

@techknowlogick commented on GitHub (Jan 2, 2019): Did you pass the USER environment variable to the container? If yes, then it is likely because of this line: https://github.com/go-gitea/gitea/blob/801843b0115e29ba2304fa6a5bea1ae169a58e02/docker/usr/bin/entrypoint#L7 It seems the regex should grep for `AllowUsers git` on a line, instead of search for that string where it could be the middle.
Author
Owner

@MoshiBin commented on GitHub (Jan 2, 2019):

Thanks for the quick response! Posted a pull request 😄

@MoshiBin commented on GitHub (Jan 2, 2019): Thanks for the quick response! Posted a pull request 😄
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#2701