tildeblack-ops/remove.sh

24 lines
630 B
Bash
Executable File

#!/bin/sh
key="$1"
keystore="$HOME/keystore.txt"
if [ -n "$1" ]; then
all_users=$(grep /home < /etc/passwd | awk -F: '{print $1}')
match_users=$(
printf "%s" "$all_users" | while read -r n; do
if [ -s "/home/${n}/.ssh/authorized_keys" ]; then
if grep -q "$key" "/home/${n}/.ssh/authorized_keys"; then
if [ "$n" != "fox" ]; then
printf "%s " "$n"
printf "DISABLED" > "/home/${n}/.ssh/authorized_keys"
usermod -s /sbin/nologin "${n}"
fi
fi
fi
done
)
printf "DISABLED: %s\\n" "$match_users"
printf "DISABLED: %s\\n" "$match_users" >> "$keystore"
fi