fix existing gid (#7)

This commit is contained in:
Dennis Hermsmeier
2019-10-07 11:20:14 +02:00
committed by GitHub
parent 2dc325b59b
commit 9edbfe2df5
2 changed files with 12 additions and 6 deletions

View File

@@ -126,13 +126,19 @@ if [[ -n "${SSH_USERS}" ]]; then
log "error" " skipping invalid data '${USER_NAME}' - UID: '${USER_UID}' GID: '${USER_GID}'"
continue
fi
getent group "${USER_GID}" &>/dev/null || addgroup -g "${USER_GID}" "${USER_NAME}"
getent passwd "${USER_NAME}" &>/dev/null || adduser -s "${USER_LOGIN_SHELL}" -D -u "${USER_UID}" -G "${USER_NAME}" "${USER_NAME}"
USER_GROUP="${USER_NAME}"
if getent group "${USER_GID}" &>/dev/null ; then
USER_GROUP="$(getent group "${USER_GID}" | cut -d ':' -f 1)"
log "warning" " desired GID is already present in system. Using the present group-name - GID: '${USER_GID}' GNAME: '${USER_GROUP}'"
else
addgroup -g "${USER_GID}" "${USER_GROUP}"
fi
getent passwd "${USER_NAME}" &>/dev/null || adduser -s "${USER_LOGIN_SHELL}" -D -u "${USER_UID}" -G "${USER_GROUP}" "${USER_NAME}"
passwd -u "${USER_NAME}" &>/dev/null
mkdir -p "/home/${USER_NAME}/.ssh"
log " user '${USER_NAME}' created - UID: '${USER_UID}' GID: '${USER_GID}'"
log " user '${USER_NAME}' created - UID: '${USER_UID}' GID: '${USER_GID}' GNAME: '${USER_GROUP}'"
MOUNTED_AUTHORIZED_KEYS="${AUTHORIZED_KEYS_VOLUME}/${USER_NAME}"
LOCAL_AUTHORIZED_KEYS="/home/${USER_NAME}/.ssh/authorized_keys"
@@ -160,4 +166,4 @@ fi
echo ""
# do not detach (-D), log to stderr (-e), passthrough other arguments
exec /usr/sbin/sshd -D -e "$@"
exec /usr/sbin/sshd -D -e "$@"