summaryrefslogtreecommitdiff
path: root/useraddhook/customize.sh
diff options
context:
space:
mode:
authorJohannes Schauer Marin Rodrigues <josch@mister-muffin.de>2023-01-03 16:00:12 +0100
committerJohannes Schauer Marin Rodrigues <josch@mister-muffin.de>2023-01-04 06:51:27 +0100
commitb208e7bcaf9297190eae44f56f00849ed0c685d0 (patch)
tree42a973880a55bc0a184c0ce1f7c3155aeb9263b8 /useraddhook/customize.sh
parent59f9267f6f884afc9b90d6040365176fb455f30c (diff)
downloaddebvm-b208e7bcaf9297190eae44f56f00849ed0c685d0.tar.gz
add useraddhook/customize.sh
- the new user is called "user" - no password required for login - requires the passwd package installed inside the chroot - this adds the new user to the sudo group if it exists - 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
Diffstat (limited to 'useraddhook/customize.sh')
-rwxr-xr-xuseraddhook/customize.sh34
1 files changed, 34 insertions, 0 deletions
diff --git a/useraddhook/customize.sh b/useraddhook/customize.sh
new file mode 100755
index 0000000..a4390bd
--- /dev/null
+++ b/useraddhook/customize.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+# Copyright 2023 Johannes Schauer Marin Rodrigues <josch@debian.org>
+# SPDX-License-Identifier: MIT
+#
+# 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"
+# - 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
+#
+# Example usage:
+#
+# $ debvm-create -p sudo -k ~/.ssh/id_rsa.pub -- --hook-dir=.../useraddhook
+# $ debvm-run -s 8022
+# $ ssh -l user -p 8022 127.0.0.1 whoami
+# user
+# $ ssh -l user -p 8022 127.0.0.1 sudo whoami
+# root
+#
+
+set -eu
+
+chroot "$1" useradd --home-dir /home/user --create-home --shell /bin/bash user
+chroot "$1" passwd --delete user
+if chroot "$1" getent group sudo >/dev/null; then
+ chroot "$1" usermod --append --groups sudo user
+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
+fi