From c8fe5864c2106fd424b2194ddcd774986cd1640d Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Thu, 28 Mar 2024 15:53:41 +0100 Subject: useraddhook: make username customizable --- useraddhook/customize.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/useraddhook/customize.sh b/useraddhook/customize.sh index 3bba263..14230a2 100755 --- a/useraddhook/customize.sh +++ b/useraddhook/customize.sh @@ -5,7 +5,7 @@ # 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 $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 @@ -23,12 +23,14 @@ set -eu -chroot "$1" useradd --home-dir /home/user --create-home --shell /bin/bash user -chroot "$1" passwd --delete user +: "${USERNAME:=user}" + +chroot "$1" useradd --home-dir "/home/$USERNAME" --create-home --shell /bin/bash "$USERNAME" +chroot "$1" passwd --delete "$USERNAME" if chroot "$1" getent group sudo >/dev/null; then - chroot "$1" usermod --append --groups sudo user + chroot "$1" usermod --append --groups sudo "$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 + chroot "$1" install -o "$USERNAME" -g "$USERNAME" -m 700 -d "/home/$USERNAME/.ssh" + chroot "$1" install -o "$USERNAME" -g "$USERNAME" -t "/home/$USERNAME/.ssh" /root/.ssh/authorized_keys fi -- cgit v1.2.3 From da2d22d423c5085cd65f30f53a0658b6e5e05c71 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Thu, 28 Mar 2024 16:02:33 +0100 Subject: autologinhook: automatically log in with lightdm --- useraddhook/customize.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/useraddhook/customize.sh b/useraddhook/customize.sh index 14230a2..d405b72 100755 --- a/useraddhook/customize.sh +++ b/useraddhook/customize.sh @@ -10,6 +10,7 @@ # - 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: # @@ -34,3 +35,10 @@ if [ -e "$1"/root/.ssh/authorized_keys ]; then chroot "$1" install -o "$USERNAME" -g "$USERNAME" -m 700 -d "/home/$USERNAME/.ssh" chroot "$1" install -o "$USERNAME" -g "$USERNAME" -t "/home/$USERNAME/.ssh" /root/.ssh/authorized_keys fi +if [ -e "$1/etc/lightdm/lightdm.conf" ]; then + cat >>"$1/etc/lightdm/lightdm.conf" < Date: Thu, 28 Mar 2024 16:03:06 +0100 Subject: useraddhook: tell which customizations are performed --- useraddhook/customize.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/useraddhook/customize.sh b/useraddhook/customize.sh index d405b72..bc827a7 100755 --- a/useraddhook/customize.sh +++ b/useraddhook/customize.sh @@ -29,13 +29,16 @@ set -eu chroot "$1" useradd --home-dir "/home/$USERNAME" --create-home --shell /bin/bash "$USERNAME" chroot "$1" passwd --delete "$USERNAME" if chroot "$1" getent group sudo >/dev/null; then + echo "Adding $USERNAME to sudo group" chroot "$1" usermod --append --groups sudo "$USERNAME" fi if [ -e "$1"/root/.ssh/authorized_keys ]; then + echo "Installing ssh authorized_keys for $USERNAME" chroot "$1" install -o "$USERNAME" -g "$USERNAME" -m 700 -d "/home/$USERNAME/.ssh" chroot "$1" install -o "$USERNAME" -g "$USERNAME" -t "/home/$USERNAME/.ssh" /root/.ssh/authorized_keys fi if [ -e "$1/etc/lightdm/lightdm.conf" ]; then + echo "Enabling autologin in lightdm for $USERNAME" cat >>"$1/etc/lightdm/lightdm.conf" < Date: Wed, 15 May 2024 06:50:36 +0200 Subject: useraddhook: rename USERNAME environment variable to be less generic USERNAME has uses beyond e.g. in a Windows context, so avoid that. Then again, this hook may be useful beyond debvm and is installed to /usr/share/mmdebstrap, so don't use a DEBVM_ prefix either. Reported-by: Johannes Schauer Marin Rodrigues --- useraddhook/customize.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/useraddhook/customize.sh b/useraddhook/customize.sh index bc827a7..ec85d0a 100755 --- a/useraddhook/customize.sh +++ b/useraddhook/customize.sh @@ -5,7 +5,7 @@ # 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" by default (customizable via $USERNAME) +# - 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 @@ -24,24 +24,24 @@ set -eu -: "${USERNAME:=user}" +: "${USERADDHOOK_USERNAME:=user}" -chroot "$1" useradd --home-dir "/home/$USERNAME" --create-home --shell /bin/bash "$USERNAME" -chroot "$1" passwd --delete "$USERNAME" +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 - echo "Adding $USERNAME to sudo group" - chroot "$1" usermod --append --groups sudo "$USERNAME" + echo "Adding $USERADDHOOK_USERNAME to sudo group" + chroot "$1" usermod --append --groups sudo "$USERADDHOOK_USERNAME" fi if [ -e "$1"/root/.ssh/authorized_keys ]; then - echo "Installing ssh authorized_keys for $USERNAME" - chroot "$1" install -o "$USERNAME" -g "$USERNAME" -m 700 -d "/home/$USERNAME/.ssh" - chroot "$1" install -o "$USERNAME" -g "$USERNAME" -t "/home/$USERNAME/.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 $USERNAME" + echo "Enabling autologin in lightdm for $USERADDHOOK_USERNAME" cat >>"$1/etc/lightdm/lightdm.conf" <