summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2024-03-28 15:53:41 +0100
committerHelmut Grohne <helmut@subdivi.de>2024-03-28 15:53:41 +0100
commitc8fe5864c2106fd424b2194ddcd774986cd1640d (patch)
treee60466a9699ba9eb8cab9662b77a978b5d1f9118
parent94049a0c052bea97728058cd84ba7a9002e10d2e (diff)
downloaddebvm-c8fe5864c2106fd424b2194ddcd774986cd1640d.tar.gz
useraddhook: make username customizable
-rwxr-xr-xuseraddhook/customize.sh14
1 files 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