Repository navigation
Conversation
Add `gotify user create [--admin] <name> [password]`, `gotify user set-password <name> [password]` and `gotify user set-admin <name> true|false`. They load the same config as `gotify serve` and operate directly on the configured database, so a lost admin account can be recovered without API access. If the password is omitted, it is prompted for twice without echo. If stdin is not a terminal, the command fails instead of hanging. Passwords are validated and hashed like in the API. The commands never create the default user, so on an empty database only the requested change is made. Fixes gotify#1043
This was referenced Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1043
This adds the
usersubcommands that @jmattheis proposed in the issue, so a lost admin account can be recovered without access to the API:If
[password]is omitted, it is prompted for twice without echo. If stdin isn't a terminal, the command exits with an error instead of hanging. Passwords go through the sameValidateNewPassword/CreatePassword(withGOTIFY_PASSSTRENGTH) as the API. The commands load the config exactly likeserve(env vars and env files), so they hit the same database.Example, recovering the admin in Docker:
Some notes:
createDefaultUserIfNotExist=false, so running a command against an empty database doesn't also createadmin:admin. It only makes the requested change.set-admin <name> falsecurrently follows the spec and doesn't stop you from demoting the last admin, while the API refuses that ("cannot delete last admin"). I can add the same check here if you'd prefer. You could always promote a user again with the CLI.golang.org/x/termfor the password prompt, at the versionx/cryptoalready requires.I tested on a clean Ubuntu 24.04 VM with Go 1.27.4:
make test-coverageandmake check-go(golangci-lint v2.15.0)serve, rancreate(argument and real terminal prompt),create --admin,set-password adminandset-admin alice true, then checked over the API that the old admin password returns 401, the new one 200, and alice is admin. Also checked all the error cases and their exit codes.docker/Dockerfileand recovered the admin withdocker exec -it gotify ./gotify-app user set-password admin.set-password,createandset-admin, then verified via the API.Docs: gotify/website#110 describes how to reset a lost admin password with these commands.