Expect user 'gitea' but current user is: #2310

Closed
opened 2025-11-02 04:32:12 -06:00 by GiteaMirror · 7 comments
Owner

Originally created by @tinxx on GitHub (Sep 8, 2018).

  • Gitea version (or commit ref): 1.5.1
  • Git version: 2.18.0
  • Operating system: Alpine Linux v3.8
  • 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

Gitea is unable to identify current user on Alpine Linux.
I have build a simple docker container using Alpine Linux to run the official release of Gitea taken from dl.gitea.io. Problem is that it does not seem to be able to identify current user, so if I set a RUN_USER in app.ini, all I get is the following error message:

2018/09/08 12:20:59 [...s/setting/setting.go:990 NewContext()] [E] Expect user 'gitea' but current user is: 

Gitea runs if you omit setting RUN_USER, but it uses empty user name in ssh strings, too, like so: ssh://@domain.tld/RepoName.git

Originally created by @tinxx on GitHub (Sep 8, 2018). - Gitea version (or commit ref): 1.5.1 - Git version: 2.18.0 - Operating system: Alpine Linux v3.8 - 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 Gitea is unable to identify current user on Alpine Linux. I have build a simple docker container using Alpine Linux to run the official release of Gitea taken from `dl.gitea.io`. Problem is that it does not seem to be able to identify current user, so if I set a `RUN_USER` in `app.ini`, all I get is the following error message: ``` 2018/09/08 12:20:59 [...s/setting/setting.go:990 NewContext()] [E] Expect user 'gitea' but current user is: ``` Gitea runs if you omit setting `RUN_USER`, but it uses empty user name in ssh strings, too, like so: `ssh://@domain.tld/RepoName.git`
GiteaMirror added the type/enhancementissue/duplicate labels 2025-11-02 04:32:12 -06:00
Author
Owner

@SagePtr commented on GitHub (Sep 8, 2018):

Now gitea relies on USER environment variable (don't know why, it can easily be spoofed).
So try to run
USER=gitea /path/to/gitea web

Maybe this should be fixed and CurrentUsername function should use Current() function from "os/user" to determine actual username rather than looking at USER environment variable?

@SagePtr commented on GitHub (Sep 8, 2018): Now gitea relies on USER environment variable (don't know why, it can easily be spoofed). So try to run ```USER=gitea /path/to/gitea web``` Maybe this should be fixed and CurrentUsername function should use Current() function from "[os/user](https://golang.org/pkg/os/user/#Current)" to determine actual username rather than looking at ```USER``` environment variable?
Author
Owner

@tinxx commented on GitHub (Sep 9, 2018):

So try to run

USER=gitea /path/to/gitea web

@SagePtr, it actually solved the problem, thanks!

EDIT:
A follow-up problem is that ssh connection is not possible. This is due to the same problem, as gitea is called as part of the auth (ref. .ssh/authorized_keys).

EDIT 2:
I have added ENV USER=gitea to my Dockerfile for the time being :)

Hi there, You've successfully authenticated, but Gitea does not provide shell access.
If this is unexpected, please log in with password and setup Gitea under another user.

EDIT 3:
I don't know (yet) what exactly Gitea does after ssh login but it is probably not portable across busybox. This is what I see:

halt: unrecognized option: c
BusyBox v1.28.4 (2018-07-17 15:21:40 UTC) multi-call binary.

Usage: halt [-d DELAY] [-n] [-f]

Halt the system

	-d SEC	Delay interval
	-n	Do not sync
	-f	Force (don't go through init)
@tinxx commented on GitHub (Sep 9, 2018): > So try to run > ``` > USER=gitea /path/to/gitea web > ``` @SagePtr, it actually solved the problem, thanks! **EDIT:** A follow-up problem is that ssh connection is not possible. This is due to the same problem, as gitea is called as part of the auth (ref. `.ssh/authorized_keys`). **EDIT 2:** I have added `ENV USER=gitea` to my Dockerfile for the time being :) > Hi there, You've successfully authenticated, but Gitea does not provide shell access. > If this is unexpected, please log in with password and setup Gitea under another user. **EDIT 3:** I don't know (yet) what exactly Gitea does after ssh login but it is probably not portable across busybox. This is what I see: ``` halt: unrecognized option: c BusyBox v1.28.4 (2018-07-17 15:21:40 UTC) multi-call binary. Usage: halt [-d DELAY] [-n] [-f] Halt the system -d SEC Delay interval -n Do not sync -f Force (don't go through init) ```
Author
Owner

@adelowo commented on GitHub (Sep 9, 2018):

A follow-up problem is that ssh connection is not possible. This is due to the same problem, as gitea is called as part of the auth (ref. .ssh/authorized_keys).

ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no server@IP

@adelowo commented on GitHub (Sep 9, 2018): > A follow-up problem is that ssh connection is not possible. This is due to the same problem, as gitea is called as part of the auth (ref. .ssh/authorized_keys). `ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no server@IP`
Author
Owner

@SagePtr commented on GitHub (Sep 9, 2018):

Try setting HOME environment variable as well, probably it relies on it when accessing .ssh/authorized_keys file

@SagePtr commented on GitHub (Sep 9, 2018): Try setting ```HOME``` environment variable as well, probably it relies on it when accessing .ssh/authorized_keys file
Author
Owner

@tinxx commented on GitHub (Sep 9, 2018):

No, I think you misunderstood. HOME is already set. The problem must be something Gitea executes after SSH auth is granted.

EDIT:
I fixed it by installing and providing dash as default shell for user gitea. We could still consider fixing busybox compatibility.

I think I'm fine now. Thanks for your help! :)

EDIT 2:
Sadly, I was mistaken. Gitea seems to rely on bash after. Pull worked just fine but this happens when trying to push:

remote: env: can't execute 'bash': No such file or directory

EDIT 3:
I replaced dash with bash in my previous fix (see above) and all seems to be good now.

I think, though, that Gitea should be made POSIX compliant so it could run on any standard shell!

@tinxx commented on GitHub (Sep 9, 2018): No, I think you misunderstood. `HOME` is already set. The problem must be something Gitea executes after SSH auth is granted. **EDIT:** I fixed it by installing and providing `dash` as default shell for user gitea. We could still consider fixing busybox compatibility. I think I'm fine now. Thanks for your help! :) **EDIT 2:** Sadly, I was mistaken. Gitea seems to rely on `bash` after. Pull worked just fine but this happens when trying to push: ``` remote: env: can't execute 'bash': No such file or directory ``` **EDIT 3:** I replaced `dash` with `bash` in my previous fix (see above) and all seems to be good now. I think, though, that Gitea should be made POSIX compliant so it could run on any standard shell!
Author
Owner

@techknowlogick commented on GitHub (Sep 10, 2018):

Closing as dupe of #1640

@techknowlogick commented on GitHub (Sep 10, 2018): Closing as dupe of #1640
Author
Owner

@bboysoulcn commented on GitHub (Jun 6, 2019):

write a shell script and
docker exec -it gogs cat /data/gogs/backup.sh
shell content

#!/bin/bash
su - git -s /bin/bash -c "/app/gogs/gogs backup"
@bboysoulcn commented on GitHub (Jun 6, 2019): write a shell script and `docker exec -it gogs cat /data/gogs/backup.sh` shell content ``` #!/bin/bash su - git -s /bin/bash -c "/app/gogs/gogs backup" ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#2310