Further changed death mechanics, now fully functional

This commit is contained in:
sose 2018-10-15 05:20:18 +02:00
parent b7bbe1ccc6
commit 0ff808414e
7 changed files with 26 additions and 22 deletions

6
deathwatch.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
inotifywait -mrqe delete users | while read dir
do
echo "$dir" | grep -q 'ISDIR .ssh' \
&& ./deluser.sh "$(echo $dir | cut -f 2 -d '/')"
done

View File

@ -3,7 +3,7 @@ SLBRUSER=$1
test -z "$SLBRUSER" && echo "no user provided" && exit test -z "$SLBRUSER" && echo "no user provided" && exit
if !(grep -qE "^$SLBRUSER$" users.txt) if !(grep -qE "^$SLBRUSER$" users.txt)
then then
echo "user not found in users.txt, will not delete" echo "user $SLBRUSER not found in users.txt, will not delete"
exit exit
fi fi
@ -15,7 +15,7 @@ then
fi fi
lxc stop "$SLBRUSER" lxc stop "$SLBRUSER"
lxc delete "$SLBRUSER" lxc delete "$SLBRUSER"
sudo rm -rf "$SLBRUSER" sudo rm -rf "/home/slbr/users/$SLBRUSER"
sudo userdel "$SLBRUSER" sudo userdel "$SLBRUSER"
sed -i "s/^$SLBRUSER$//g" users.txt sed -i "s/^$SLBRUSER$//g" users.txt
sed -i '/^$/d' users.txt sed -i '/^$/d' users.txt

View File

@ -1 +1 @@
1

View File

@ -8,9 +8,7 @@ then
exit exit
fi fi
rm -rf "/home/sblr/$SLBRUSER" echo "removing /home/slbr/users/$SLBRUSER"
userdel "$SLBRUSER" rm -rf "/home/slbr/users/$SLBRUSER/.ssh"
sed -i "s/^$SLBRUSER$//g" /home/slbr/users.txt sleep 10
sed -i '/^$/d' /home/slbr/users.txt lxc delete -f "$SLBRUSER"
lxc stop "$SLBRUSER"
lxc delete "$SLBRUSER"

View File

@ -12,6 +12,6 @@ echo "READY.......BEGIN!"
sleep 1 sleep 1
echo "Setting up your container..." echo "Setting up your container..."
lxc exec "$SLBRUSER" ssh-keygen -- -t rsa -N '' -f /root/.ssh/id_rsa lxc exec "$SLBRUSER" ssh-keygen -- -t rsa -N '' -f /root/.ssh/id_rsa
lxc file pull "$SLBRUSER/root/.ssh/id_rsa.pub" "/home/slbr/$SLBRUSER/pubkey.temp" lxc file pull "$SLBRUSER/root/.ssh/id_rsa.pub" "/home/slbr/users/$SLBRUSER/pubkey.temp"
cat "/home/slbr/$SLBRUSER/pubkey.temp" >> "/home/slbr/$SLBRUSER/.ssh/authorized_keys" && rm "/home/slbr/$SLBRUSER/pubkey.temp" cat "/home/slbr/users/$SLBRUSER/pubkey.temp" >> "/home/slbr/users/$SLBRUSER/.ssh/authorized_keys" && rm "/home/slbr/users/$SLBRUSER/pubkey.temp"
lxc exec "$SLBRUSER" /usr/bin/tmuxinit.sh lxc exec "$SLBRUSER" /usr/bin/tmuxinit.sh

View File

@ -8,22 +8,22 @@ PUBKEY="$(cat "$PUBKEY")"
cut -d: -f1 /etc/passwd | grep -qx "$SLBRUSER" && echo "user already exists" && exit cut -d: -f1 /etc/passwd | grep -qx "$SLBRUSER" && echo "user already exists" && exit
echo "Creating homedir..." echo "Creating homedir..."
mkdir "/home/slbr/$SLBRUSER" mkdir "/home/slbr/users/$SLBRUSER"
mkdir "/home/slbr/$SLBRUSER/.ssh" mkdir "/home/slbr/users/$SLBRUSER/.ssh"
echo "Copying key..." echo "Copying key..."
echo "$PUBKEY" >> "/home/slbr/$SLBRUSER/.ssh/authorized_keys" echo "$PUBKEY" >> "/home/slbr/users/$SLBRUSER/.ssh/authorized_keys"
echo "Creating container..." echo "Creating container..."
echo "lxc exec $SLBRUSER bash" > "/home/slbr/$SLBRUSER/.profile" echo "lxc exec $SLBRUSER bash" > "/home/slbr/users/$SLBRUSER/.profile"
chmod -w "/home/slbr/$SLBRUSER/.profile" chmod -w "/home/slbr/users/$SLBRUSER/.profile"
echo "Creating user..." echo "Creating user..."
sudo useradd "$SLBRUSER" -d "/home/slbr/$SLBRUSER" sudo useradd "$SLBRUSER" -d "/home/slbr/users/$SLBRUSER"
sudo usermod -a -G lxd "$SLBRUSER" sudo usermod -a -G lxd "$SLBRUSER"
sudo cp ./killme.sh "/home/slbr/$SLBRUSER/killme.sh" sudo cp ./killme.sh "/home/slbr/users/$SLBRUSER/killme.sh"
sudo chmod +x "/home/slbr/$SLBRUSER" sudo chmod +x "/home/slbr/users/$SLBRUSER"
sudo chown -R "$SLBRUSER:$SLBRUSER" "/home/slbr/$SLBRUSER" sudo chown -R "$SLBRUSER:$SLBRUSER" "/home/slbr/users/$SLBRUSER"
sudo chsh "$SLBRUSER" -s /home/slbr/login.sh sudo chsh "$SLBRUSER" -s /home/slbr/login.sh
echo "Generating user keypair..." echo "Generating user keypair..."
sudo su "$SLBRUSER" -s /bin/sh -c "ssh-keygen -t rsa -N '' -f /home/slbr/$SLBRUSER/.ssh/id_rsa" sudo su "$SLBRUSER" -s /bin/sh -c "ssh-keygen -t rsa -N '' -f /home/slbr/users/$SLBRUSER/.ssh/id_rsa"
echo "Initializing container..." echo "Initializing container..."
sudo su "$SLBRUSER" -s /bin/sh -c "/home/slbr/lxcinit.sh" sudo su "$SLBRUSER" -s /bin/sh -c "/home/slbr/lxcinit.sh"
echo "$SLBRUSER" >> users.txt echo "$SLBRUSER" >> users.txt

View File

@ -54,7 +54,7 @@ if [ ! -e "$HOME/.sudo_as_admin_successful" ] && [ ! -e "$HOME/.hushlogin" ] ; t
fi fi
function command_not_found_handle { function command_not_found_handle {
ssh testuser@10.123.168.1 ssh -o "StrictHostKeyChecking no" testuser@10.123.168.1 &
echo "====YOU HAVE BEEN ELIMINATED====" echo "====YOU HAVE BEEN ELIMINATED===="
sleep 2 sleep 2
} }