VPS bootstrap: unlock the deploy user and give it passwordless sudo #1
@@ -313,6 +313,29 @@ elif getent group wheel >/dev/null 2>&1; then
|
|||||||
usermod -aG wheel "${DEPLOY_USER}"
|
usermod -aG wheel "${DEPLOY_USER}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# useradd leaves the password field as "!" (locked). With UsePAM no (set during
|
||||||
|
# hardening) sshd then rejects even key logins: "account is locked".
|
||||||
|
# "*" = no password but not locked.
|
||||||
|
if [[ "$(getent shadow "${DEPLOY_USER}" | cut -d: -f2)" =~ ^!+\*?$ ]]; then
|
||||||
|
usermod -p '*' "${DEPLOY_USER}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Key-only user has no password to type, so sudo must not ask for one.
|
||||||
|
if [[ "${DEPLOY_USER}" != "root" ]]; then
|
||||||
|
if ! command -v sudo >/dev/null 2>&1 && command -v apt-get >/dev/null 2>&1; then
|
||||||
|
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq sudo >/dev/null
|
||||||
|
fi
|
||||||
|
SUDOERS="/etc/sudoers.d/90-rubix-${DEPLOY_USER}"
|
||||||
|
echo "${DEPLOY_USER} ALL=(ALL) NOPASSWD:ALL" > "${SUDOERS}.tmp"
|
||||||
|
chmod 440 "${SUDOERS}.tmp"
|
||||||
|
if visudo -cf "${SUDOERS}.tmp" >/dev/null; then
|
||||||
|
mv "${SUDOERS}.tmp" "${SUDOERS}"
|
||||||
|
else
|
||||||
|
rm -f "${SUDOERS}.tmp"
|
||||||
|
echo "WARN: sudoers check failed, ${DEPLOY_USER} has no passwordless sudo" >&2
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
install_key_for_user() {
|
install_key_for_user() {
|
||||||
local u="$1"
|
local u="$1"
|
||||||
local home_dir
|
local home_dir
|
||||||
|
|||||||
Reference in New Issue
Block a user