From 1abf7f48e29ab262409774526950fd2adf5a0ee3 Mon Sep 17 00:00:00 2001 From: Oliver Atkinson Date: Thu, 14 Dec 2023 02:45:44 -0700 Subject: [PATCH] fix up home dir handling --- .local/bin/chroot-gen | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/.local/bin/chroot-gen b/.local/bin/chroot-gen index fdba8ca..aaa7e34 100755 --- a/.local/bin/chroot-gen +++ b/.local/bin/chroot-gen @@ -9,17 +9,26 @@ CMDS=($CMDS) # convert to array if ! id "$USER" 2&>/dev/null; then echo 'INFO: User not found' echo 'Creating...' - useradd -m $USER + useradd $USER echo "Password for $USER:" passwd $USER fi CHROOT=$(eval echo ~$USER) + +mkdir -p $CHROOT$CHROOT # make new home dir +chown $USER:$USER $CHROOT$CHROOT + # ChrootDirectory requires these permissions chown root:root $CHROOT chmod 745 $CHROOT printf "Match User $USER\n ChrootDirectory $CHROOT" > /etc/ssh/sshd_config.d/70-$USER.conf +# cp user and group into chroot +mkdir -p $CHROOT/etc/ +cat /etc/passwd | grep $USER > $CHROOT/etc/passwd +cat /etc/group | grep $USER > $CHROOT/etc/group + # cp in all commands and dependencies for cmd in "${CMDS[@]}"; do for dep in $( ldd $(which $cmd) | grep -v dynamic | cut -d " " -f 3 | sed 's/://' | sort | uniq ); do @@ -28,12 +37,6 @@ for cmd in "${CMDS[@]}"; do cp --parents $(which $cmd) $CHROOT done -# cp user and group into chroot -mkdir -p $CHROOT/etc/ -cat /etc/passwd | grep $USER > $CHROOT/etc/passwd -cat /etc/group | grep $USER > $CHROOT/etc/group -mkdir -p $CHROOT$CHROOT # make new home dir - SHELL=$(cat /etc/passwd | grep $USER | tr ":" "\n" | tail -n 1) if [ ! -f $CHROOT$SHELL ]; then echo "WARN: You didn't add the shell specified in /etc/passwd for \"$USER\": ($SHELL)"