Enable SSH and no-login access to public repos

This commit is contained in:
alejo committed 2026-10-25 13:49:30 -03:00
1 parent 877fa4a879
commit 416e87fa8a
2 files changed
+48 -4

No files matched your search

+29 -2
View File
@@ -289,10 +289,27 @@ create_git_user() {
fi
# Use what the system really has (matters when the user already existed).
local entry
local entry configured_default
configured_default="$GITEA_HOME" # the script's own default/--env-var choice, before we overwrite it below
entry="$(getent passwd "$GITEA_USER")"
GITEA_HOME="$(cut -d: -f6 <<<"$entry")"
GITEA_GROUP="$(id -gn "$GITEA_USER")"
# A pre-existing 'git' account (made by some other package, a bare distro
# default, or an earlier partial install) commonly has NO real home
# directory: 'useradd --system' without --create-home still records a path
# in /etc/passwd but never creates it on disk. Left alone, every path this
# script builds from GITEA_HOME (repos, authorized_keys) lands wherever
# that missing path's nearest existing ancestor is -- for a bare, never-
# created path that resolves to the filesystem root. Fix it in place.
if [[ -z "$GITEA_HOME" || "$GITEA_HOME" == "/" || ! -d "$GITEA_HOME" ]]; then
warn "User '${GITEA_USER}' has no real home directory (passwd says '${GITEA_HOME:-<empty>}'); creating ${configured_default} and pointing the account at it."
mkdir -p -- "$configured_default"
chown "${GITEA_USER}:${GITEA_GROUP}" "$configured_default"
usermod --home "$configured_default" "$GITEA_USER"
GITEA_HOME="$configured_default"
fi
case "$(cut -d: -f7 <<<"$entry")" in
*/nologin|*/false|*/git-shell)
warn "User '${GITEA_USER}' has a non-interactive login shell, so SSH pushes will fail. Fix: usermod -s /bin/bash ${GITEA_USER}"
@@ -420,6 +437,10 @@ START_SSH_SERVER = false
SSH_DOMAIN = ${GITEA_DOMAIN}
SSH_PORT = ${GITEA_SSH_PORT}
SSH_CREATE_AUTHORIZED_KEYS_FILE = true
; Show the SSH clone URL on a public repo's page to visitors who aren't
; signed in (an anonymous key still can't push or read a private repo --
; this only affects whether the URL itself is displayed).
SSH_EXPOSE_ANONYMOUS = true
LFS_START_SERVER = true
LFS_JWT_SECRET = ${lfs_jwt_secret}
@@ -444,7 +465,10 @@ JWT_SECRET = ${oauth2_jwt_secret}
[service]
DISABLE_REGISTRATION = ${GITEA_DISABLE_REGISTRATION}
REQUIRE_SIGNIN_VIEW = true
; false (GitHub-style): public repos can be browsed and cloned over HTTP(S)
; without signing in. Private repos still require auth either way -- this
; only affects whether the sign-in wall covers public content too.
REQUIRE_SIGNIN_VIEW = false
DEFAULT_KEEP_EMAIL_PRIVATE = true
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
@@ -452,6 +476,9 @@ DEFAULT_ALLOW_CREATE_ORGANIZATION = true
MODE = console
LEVEL = info
ROOT_PATH = ${GITEA_WORK_DIR}/log
; Logs each SSH (git serv) connection -- who connected and which key/repo --
; the SSH-side counterpart of the HTTP access log.
ENABLE_SSH_LOG = true
EOF
}