fix up home dir handling
This commit is contained in:
		@@ -9,17 +9,26 @@ CMDS=($CMDS) # convert to array
 | 
				
			|||||||
if ! id "$USER" 2&>/dev/null; then
 | 
					if ! id "$USER" 2&>/dev/null; then
 | 
				
			||||||
	echo 'INFO: User not found'
 | 
						echo 'INFO: User not found'
 | 
				
			||||||
	echo 'Creating...'
 | 
						echo 'Creating...'
 | 
				
			||||||
	useradd -m $USER
 | 
						useradd $USER
 | 
				
			||||||
	echo "Password for $USER:"
 | 
						echo "Password for $USER:"
 | 
				
			||||||
	passwd $USER
 | 
						passwd $USER
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CHROOT=$(eval echo ~$USER)
 | 
					CHROOT=$(eval echo ~$USER)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					mkdir -p $CHROOT$CHROOT # make new home dir
 | 
				
			||||||
 | 
					chown $USER:$USER $CHROOT$CHROOT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# ChrootDirectory requires these permissions 
 | 
					# ChrootDirectory requires these permissions 
 | 
				
			||||||
chown root:root $CHROOT
 | 
					chown root:root $CHROOT
 | 
				
			||||||
chmod 745 $CHROOT
 | 
					chmod 745 $CHROOT
 | 
				
			||||||
printf "Match User $USER\n 	ChrootDirectory $CHROOT" > /etc/ssh/sshd_config.d/70-$USER.conf
 | 
					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 
 | 
					# cp in all commands and dependencies 
 | 
				
			||||||
for cmd in "${CMDS[@]}"; do
 | 
					for cmd in "${CMDS[@]}"; do
 | 
				
			||||||
	for dep in $( ldd $(which $cmd) | grep -v dynamic | cut -d " " -f 3 | sed 's/://' | sort | uniq ); 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
 | 
						cp --parents $(which $cmd) $CHROOT
 | 
				
			||||||
done
 | 
					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)
 | 
					SHELL=$(cat /etc/passwd | grep $USER | tr ":" "\n" | tail -n 1)
 | 
				
			||||||
if [ ! -f $CHROOT$SHELL ]; then 
 | 
					if [ ! -f $CHROOT$SHELL ]; then 
 | 
				
			||||||
	echo "WARN: You didn't add the shell specified in /etc/passwd for \"$USER\": ($SHELL)"
 | 
						echo "WARN: You didn't add the shell specified in /etc/passwd for \"$USER\": ($SHELL)"
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user