summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Grohne <helmutg@debian.org>2024-05-20 15:41:16 +0000
committerHelmut Grohne <helmutg@debian.org>2024-05-20 15:41:16 +0000
commit29545ccdeaf422babefc94c452c8a7d2dccc7229 (patch)
tree805aaba8f0b824a4c3e0eff641eba1cd6f48578e
parente87e5a8fa9faa5f40beba12613ff2de1eab81107 (diff)
parent12c293c3e7777d425070ca140c8ab00a5c7a4883 (diff)
downloaddebvm-29545ccdeaf422babefc94c452c8a7d2dccc7229.tar.gz
Merge branch 'tweak-useradd' into 'main'
Improve the useradd hook See merge request helmutg/debvm!41
-rwxr-xr-xuseraddhook/customize.sh25
1 files changed, 19 insertions, 6 deletions
diff --git a/useraddhook/customize.sh b/useraddhook/customize.sh
index 3bba263..ec85d0a 100755
--- a/useraddhook/customize.sh
+++ b/useraddhook/customize.sh
@@ -5,11 +5,12 @@
# Add a non-root user, add them to the sudo group and use the same authorized
# ssh keys as the root user.
#
-# - the new user is called "user"
+# - the new user is called "user" by default (customizable via $USERADDHOOK_USERNAME)
# - no password required for login
# - requires the passwd and coreutils packages installed inside the chroot
# - adds the new user to the sudo group if it exists
# - ~/.ssh/authorized_keys files is copied from root user if it exists
+# - enables immediate autologin via lightdm if installed
#
# Example usage:
#
@@ -23,12 +24,24 @@
set -eu
-chroot "$1" useradd --home-dir /home/user --create-home --shell /bin/bash user
-chroot "$1" passwd --delete user
+: "${USERADDHOOK_USERNAME:=user}"
+
+chroot "$1" useradd --home-dir "/home/$USERADDHOOK_USERNAME" --create-home --shell /bin/bash "$USERADDHOOK_USERNAME"
+chroot "$1" passwd --delete "$USERADDHOOK_USERNAME"
if chroot "$1" getent group sudo >/dev/null; then
- chroot "$1" usermod --append --groups sudo user
+ echo "Adding $USERADDHOOK_USERNAME to sudo group"
+ chroot "$1" usermod --append --groups sudo "$USERADDHOOK_USERNAME"
fi
if [ -e "$1"/root/.ssh/authorized_keys ]; then
- chroot "$1" install -o user -g user -m 700 -d /home/user/.ssh
- chroot "$1" install -o user -g user -t /home/user/.ssh /root/.ssh/authorized_keys
+ echo "Installing ssh authorized_keys for $USERADDHOOK_USERNAME"
+ chroot "$1" install -o "$USERADDHOOK_USERNAME" -g "$USERADDHOOK_USERNAME" -m 700 -d "/home/$USERADDHOOK_USERNAME/.ssh"
+ chroot "$1" install -o "$USERADDHOOK_USERNAME" -g "$USERADDHOOK_USERNAME" -t "/home/$USERADDHOOK_USERNAME/.ssh" /root/.ssh/authorized_keys
+fi
+if [ -e "$1/etc/lightdm/lightdm.conf" ]; then
+ echo "Enabling autologin in lightdm for $USERADDHOOK_USERNAME"
+ cat >>"$1/etc/lightdm/lightdm.conf" <<EOF
+[SeatDefaults]
+autologin-user=$USERADDHOOK_USERNAME
+autologin-user-timeout=0
+EOF
fi